I get an error from the following Python3 code on the specified lines. x, y and z - all simple numpy 2D arrays are identical, but for size and should work the same. However, they act differently: with errors y and z, and x works fine.
import numpy as np
from PIL import Image
a = np.ones( ( 3,3,3), dtype='uint8' )
x = a[1,:,:]
y = a[:,1,:]
z = a[:,:,1]
imx = Image.fromarray(x)
imy = Image.fromarray(y)
imz = Image.fromarray(z)
but it works
z1 = 1*z
imz = Image.fromarray(z1)
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python3\lib\site-packages\PIL\Image.py", line 1918, in fromarray
obj = obj.tobytes()
AttributeError: 'numpy.ndarray' object has no attribute 'tobytes'
So what is different from x, y, z, z1? Nothing I can say.
>>> z.dtype
dtype('uint8')
>>> z1.dtype
dtype('uint8')
>>> z.shape
(3, 4)
>>> z1.shape
(3, 4)
I am using Python 3.2.3 on a Windows 7 Enterprise machine with all 64-bit versions.