python用numpy生成图片并保存_将Numpy数组保存为图像(说明)

我在前一篇文章中找到了答案:Saving a Numpy array as an image。唯一的问题是,使用PyPNG模块的指令不多。

但我该怎么做呢?写下这样的错误:Traceback (most recent call last):

File "", line 1, in

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/png.py", line 638, in write

nrows = self.write_passes(outfile, rows)

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/png.py", line 783, in write_passes

extend(row)

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/png.py", line 780, in

return lambda sl: f(map(int, sl))

TypeError: argument 2 to map() must support iteration

这里是我的代码PCA_tool.py中发生错误的地方(错误出现在“folder.write(outfilename,PrincipalComponent)”之后):#PrincipalComponent.save(path+'transform_'+str(each)+'.png', format='PNG')

outfilename = open(str(path)+'transformed/transform_'+str(each)+'.png', 'wb')

folder = png.Writer(m,n,greyscale=True)

folder.write(outfilename, PrincipalComponent)

outfilename.close()

sys.exit(0)

我试图将8400元素numpy.ndarray保存为n=80列,m=105行灰度png图像。

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值