for i in range(3):
a = np.array(cos(i))
print (a)
答案 0 :(得分:0)
每次循环时,您都可以将其追加到列表中,然后稍后再访问所有值。
result_list = []
stiffness_matrix_total = np.zeros((2*nnode,2*nnode), dtype=np.float)
for i in range(nele):
ele_stiff_mat = np.zeros((2*nnode,2*nnode), dtype=np.float)
a = np.array([[cos[i,0]**2,sin[i,0]*cos[i,0],-(cos[i,0]**2),-cos[i,0]*sin[i,0]],[cos[i,0]*sin[i,0],sin[i,0]**2,-cos[i,0]*sin[i,0],-(sin[i,0]**2)],[-cos[i,0]**2,-sin[i,0]*cos[i,0],cos[i,0]**2,cos[i,0]*sin[i,0]],[-cos[i,0]*sin[i,0],-(sin[i,0]**2),cos[i,0]*sin[i,0],sin[i,0]**2]])
result_list.append(a)
print (result_list)
答案 1 :(得分:0)
有两种快速方法。可以通过将它们附加到空白列表 arr_list
上,如下所示:
n=3
arr_list=[]
for i in range(n):
arr_list.append(np.array(cos(i)))
# Here you will have List of Arrays arr_list=[a1, a2, a3]
或通过exec命令将它们分配给命名数组,以便最后有一组 a1..an
数组。但是,仅在n
很小的情况下才建议这样做。
n=3
for i in range(n):
exec("a%s = np.array(cos(i))" %i)
# Here you will have a1, a2, a3
答案 2 :(得分:0)
array_list = [[] for i in range(3)]
for i in range(3):
array_list[i] = np.array(np.cos(i))
print (array_list)
array_list
是您提供的数组的列表。