如何使用numpy保存多为数组

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,全部删除
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值