当我运行此代码时,它会按预期运行,并为我提供10张尺寸为100x100的图像:
import numpy as np
for i in range(10):
im = np.random.random_integers(0, 255, 10000).reshape((100, 100))
misc.imsave('random_%03d.png' % i, im)
但是,如果我更改参数以将其重塑为(200,200),则会收到错误消息:
ValueError: total size of new array must be unchanged
为什么会这样?为什么没有返回200x200的图片?
您可以将10000点重塑为100x100,不能将10000点重塑为200x200。这是简单的数学运算。您必须将呼叫更改为
im = np.random.random_integers(0, 255, 40000).reshape((200, 200))
请注意,您现在采样的是40000(200 * 200)点,而不是10000(100 * 100)点
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句