【发布时间】:2017-04-09 04:25:06
【问题描述】:
我有一个列表列表,我想将每个子列表分配给一个特定形状的形状数组。到目前为止,我有:
N=23
# read the file in lines
with open('ircforward.xyz','r') as f:
lines = f.read().splitlines()
# Split the whole file into a list of lists
profiles = [lines[i:i + N] for i in xrange(0, len(lines), N)]
#Convert first sublist to array skipping the first two lines
set1 = np.genfromtxt(profiles[0],skip_header=2,usecols=[1,2,3])
有没有一种方法可以生成一堆名为“set_n”的数组,其中 n 将是一个索引变量,并且具有以下内容:
for n in range (4000):
set_n = np.genfromtxt(profile[n], skip_header=2, usecols=[1,2,3])
【问题讨论】:
-
与其拥有
set_1、set_2等,只需构建一个数组集:sets[n] = np.genfromtxt(...)。或集合的字典。
标签: python arrays list loops numpy