如何从字典中删除序列号以进行进一步操作?

乘风 python 410

原文标题how to remove serial numbers from dictionary for further operations?

我刚刚将字典转换为数组……像这样

dict_t = {1: 0.1, 2: 0.2, 3: 0.3, 4: 0.4 }

这是我得到的:-

w =      [[ 1.  0.1  ]
          [ 2.  0.2  ]
          [ 3.  0.3  ]
          [ 4.  0.4  ]
          

这就是我想要的:-

问题 1 – 如何获得低于预期的结果?

w      = [[ 0.1  ]
          [ 0.2  ]
          [ 0.3  ]
          [ 0.4  ]]
          

此外,我将这些值索引为矩阵格式。

问题2 如何索引 w 的值?

对于 w 的每个值,我想要这个(F 矩阵)局部矩阵,

F = np.array([0],[wl/2],[-wll/12],[0],[wl/2],[wll/12])

此外,在所有操作 delta_F 将给出列矩阵之后,应以特定方式添加所有这些 F 矩阵以获得全局矩阵(在所需操作中显示如下)。

dof = 15
delta_F = np.zeros(15)

for i in range(w):
        F = np.array([0],[w*l/2],[-w*l*l/12],[0],[w*l/2],[w*l*l/12])
        rows, cols = dof,1
        F_temp = [([0]*cols) for i in range(rows)]
        F_temp[3i:3i+6,0] = F
        delta_F += F_temp
        print(delta_F)

所需的操作:-

在此处输入图像描述

原文链接:https://stackoverflow.com//questions/71465826/how-to-remove-serial-numbers-from-dictionary-for-further-operations

回复

我来回复
  • Sefan的头像
    Sefan 评论

    问题 1,这应该给出你想要的输出:

    dict_t = {1: 0.1, 2: 0.2, 3: 0.3, 4: 0.4 }
    output = [[v for v in dict_t.values()]]
    print(output) #[[0.1, 0.2, 0.3, 0.4]]
    
    2年前 0条评论