with open('model_data.txt', 'w') as outfile:
# I'm writing a header here just for the sake of readability
# Any line starting with "#" will be ignored by numpy.loadtxt
outfile.write('# Array shape: {0},卷积核大小,卷积核深度和卷积核数目,每一列代表一个卷积核\n'.format(data.shape))
# Iterating through a ndimensional array produces slices along
# the last axis. This is equivalent to data[i,:,:] in this case
for data_slice in data:
# The formatting string indicates that I'm writing out
# the values in left-justified columns 7 characters in width
# with 2 decimal places.
print(data_slice.shape)
outfile.write('# New slice\n')
for data_slice2 in data_slice:
print(data_slice2,data_slice2.shape)
# print(data_slice,data_slice.shape)
np.savetxt(outfile, data_slice2, fmt='%-7.2f')
# Writing out a break to indicate different slices...
outfile.write('# New slice\n')
data是数据来源,是一个三维或者四维的数组,如果是四维数组则不需要改变,如果是三维数组,需要把np.savetxt移到第二个循环上面,下面的
for data_slice2 in data_slice,全部删除
如何使用numpy保存多为数组
最新推荐文章于 2024-06-11 22:52:03 发布