List 在numpy中迭代列时缺少行
我正在尝试传递一个包含List 在numpy中迭代列时缺少行,list,List,我正在尝试传递一个包含x,y,z坐标的csvfie。我正在使用Python的NumPy包来实现这一点,如下面的代码所示: enter code here# !/usr/bin/python from __future__ import print_function import numpy as np import pandas as pd pdb_file=open('/home/josh/Documents/cordinates_all.csv') x_new_file=open('/h
x
,y
,z
坐标的csv
fie。我正在使用Python的NumPy
包来实现这一点,如下面的代码所示:
enter code here#
!/usr/bin/python
from __future__ import print_function
import numpy as np
import pandas as pd
pdb_file=open('/home/josh/Documents/cordinates_all.csv')
x_new_file=open('/home/josh/Documents/x_new_cordinates.txt','w+')
y_new_file=open('/home/josh/Documents/y_new_cordinates.txt','w+')
z_new_file=open('/home/josh/Documents/z_new_cordinates.txt','w+')
test=open('/home/josh/Documents/test.txt','w+')
cordinates=np.genfromtxt(pdb_file,delimiter=",")
###slicing each "column" on the basis of X ,Y and Z cordinates
x=cordinates[:,][:,0]
y=cordinates[:,][:,1]
z=cordinates[:,][:,2]
x_max=max(x)
x_min=min(x)
cx=(x_max-x_min)/2.0
y_max=max(y)
y_min=min(y)
cy=(y_max-y_min)/2.0
z_max=max(z)
z_min=min(z)
cz=(z_max-z_min)/2.0
###list of centre cordinates
cxyz=[cx,cy,cz]
####print(len(x),len(y),len(z))
#####print(np.isnan().any()) #check for missing values in the array
for count,elem in enumerate(y):
print(count ,file=test)
print (((x[count])*1.05),file=x_new_file)
print(count,file=test)
行只是检查我是否在count变量中得到了83366的值(我得到了)
坐标文件有83367行。使用len()
我可以验证所有x
、y
和z
列的行数是否相同。此外,使用isnan().any()
我可以验证它们没有任何NaN
或缺少值
然而,当我在每一列上循环对每一个值执行算术运算时,每一列都会得到不同数量的元素,我不知道为什么
我刚接触过NumPy
软件包,所以可能是我做错了什么
请告知
注意:我在Ubuntu
15.04的enthundcanopy
环境下使用Python 2.7。在文件对象上使用flush()解决了这个问题