我正在尝试查看 71290x71290 的numpy.float32
s 数组。当我尝试使用 matplotlib 以交互方式查看它时,我的计算机内存不足,因此我尝试将其保存为图像文件并在 ipython 之外查看它。以下应该可以工作,afaik 从阅读其他 SO 帖子:
import numpy as np
W = np.zeros((71290, 71290), dtype='float32')
from scipy.misc import imsave
imsave('test.png', W)
但最后一行给了我一个溢出错误:
溢出错误:大小不适合 int
这是完整的堆栈跟踪:
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
/home/agittens/Documents/langmodel/<ipython-input-4-bf9f2254f869> in <module>()
----> 1 imsave('test.png', W)
/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.pyc in imsave(name, arr)
160
161 """
--> 162 im = toimage(arr)
163 im.save(name)
164 return
/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.pyc in toimage(arr, high, low, cmin, cmax, pal, mode, channel_axis)
235 if mode in [None, 'L', 'P']:
236 bytedata = bytescale(data,high=high,low=low,cmin=cmin,cmax=cmax)
--> 237 image = Image.frombytes('L',shape,bytedata.tostring())
238 if pal is not None:
239 image.putpalette(asarray(pal,dtype=uint8).tostring())
/usr/lib/python2.7/dist-packages/PIL/Image.pyc in fromstring(mode, size, data, decoder_name, *args)
1795
1796 im = new(mode, size)
-> 1797 im.fromstring(data, decoder_name, args)
1798 return im
1799
/usr/lib/python2.7/dist-packages/PIL/Image.pyc in fromstring(self, data, decoder_name, *args)
589 d = _getdecoder(self.mode, decoder_name, args)
590 d.setimage(self.im)
--> 591 s = d.decode(data)
592
593 if s[0] >= 0:
OverflowError: size does not fit in an int