如何解决使用关键字在循环中连接多个数组
我通过存储在 numpy 数组中的列表获得了大量数据
np.savez("filename",r_maxes=r_maxes,x_maxes=x_maxes,r_mins=r_mins,x_mins=x_mins)
我现在想读取 npz 文件并在维护关键字的同时连接数组。我通过命令行参数将 npz 文件名列表作为列表 infiles
获取,然后尝试:
allArrays = np.load(infiles[0])
for i in range(1,len(infiles)):
print(i,infiles[i])
myArray = np.load(infiles[i])
allArrays['r_maxes'] = np.concatenate([allArrays['r_maxes'],myArray['r_maxes']])
allArrays['x_maxes'] = np.concatenate([allArrays['x_maxes'],myArray['x_maxes']])
allArrays['r_mins'] = np.concatenate([allArrays['r_mins'],myArray['r_mins']])
allArrays['x_mins'] = np.concatenate([allArrays['x_mins'],myArray['x_mins']])
并得到错误 TypeError: 'NpzFile' object does not support item assignment
所以好像我不能重复使用关键字?如何获得组合 npz 且关键字分配仍然正确?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。