我的代码如何将itertools.chain转换为numpy数组?
import math
import itertools
with open('/home/milenko/OCCAM2DMT_V3.0/13042/ITER04.iter') as f:
lines_after_19 = f.readlines()[19:]
p = []
for line in lines_after_19:
line = line.split()
line = [float(i) for i in line]
p.extend(line)
a1=p[1:81]
for i in a1:
b1=math.pow(10, i)
a2=p[83:163]
for i in a2:
b2=math.pow(10,i)
a3=p[165:245]
for i in a3:
b3=math.pow(10,i)
a4=p[247:327]
for i in a4:
b4=math.pow(10,i)
a5=p[329:409]
for i in a5:
b5=math.pow(10,i)
a6=p[411:491]
for i in a6:
b6=math.pow(10,i)
c = itertools.chain(b1, b2, b3, b4, b5, b6)
print type(c)
我需要到c转换为numpy
阵列,为reshape
,然后进一步计算。
你有很多的问题,在这里除了C'转换'到一个数组。'c'甚至不包含你想要的数据,因为'for'循环不会通过'b6'右边构建'b1'。当你从文件加载数据时,转换为numpy的最佳时机就在你的程序的开始。 – user2357112