我已经从一个文件创建了一个nd数组,如下所示:
for i in range(int(atoms)):
next(finp)
for j in range(int(ldata[2])):
aatom[i][j] = [float(x) for x in
finp.readline().strip().split()]
我希望它是一个3d数组(i,j,x
)。但事实并非如此。将其转换为numpy数组后:
atom = np.array(aatom)
print(atom.shape)
是:(250, 301)
这是i,j
的维度。但是,在我的思考过程中,它确实是三维的:
print(atom[1][1][:])
是:
[-3.995, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
我做错什么了?你知道吗
嵌套列表的长度可能不同,这迫使NumPy创建一个
dtype=object
数组,这意味着一个list
数组而不是float
比较
以及
相关问题 更多 >
编程相关推荐