阵列我在蟒使用numpy的读取csv文件:使用迭代来总结在python
import numpy as np
import csv
from StringIO import StringIO
with open ('1250_12.csv','rb') as csvfile:
data = np.genfromtxt(csvfile, dtype = None, delimiter = ',')
np.set_printoptions(threshold='nan'
打印出如下:
[['x1' 'y1' 'z1' 'x2' 'y2' 'z2' 'cost']
['5720.44' '3070.94' '2642.19' '5797.82' '3061.01' '2576.29' '102.12']
['5720.44' '3070.94' '2642.19' '5809.75' '3023.6' '2597.81' '110.4']
['5861.54' '3029.08' '2742.36' '5981.23' '3021.52' '2720.47' '121.92']
['5861.54' '3029.08' '2742.36' '5955.36' '3012.95' '2686.28' '110.49']
所以第一列属于“X1 ',第二列属于'x2'等。可以说x1,y1,z1是一个在数组中表示的向量,下面的点表示该值。正如你所看到的,每个x1,y1 ...都有多个点。现在我想将点加起来,使它成为使用迭代器的向量的总和。我如何使用迭代器来总结所有行?
这样的:
import numpy
a=numpy.array([0,1,2])
b=numpy.array([3,4,5])
a+b
array([3, 5, 7])
但是这仅仅是2个数组,如果有数百个,那么你就需要一个迭代器,而不是手动设置阵列吗?
有什么预期的输出? –
某些东西在你粘贴的代码中被切断了。 – user2357112
让我们说a = [x1,y1,z1]和b = [x2,y2,z2]并且总和为a + b,但我想使用迭代器,因此我可以处理所有行。 – Andy