Q:

Using fromarray from PIL to save an image vector of 4 channels and then re-reading it

I have an image vector v with the (100, 100, 4) dimensions. To save this image vector, I used PIL as follows. 
im = Image.fromarray(v)

The image vector is not RGB, As it have 4 channels. I got the following error.
TypeError: Cannot handle this data type

I also got few more errors. I think, there is some issue with the type of my array. The type of v vectors is as follows.
print(type(v))
<class 'numpy.ndarray'>

A:

You will get this error if your basic datatype is unacceptable to Image.fromarray(). So, for example, it will happily accept an array of unsigned 8-bit integers:
i=np.zeros((100,100,4),dtype=np.uint8)   # specify unsigned 8-bit ints

print(i.dtype)                           # prints dtype('uint8')
im = Image.fromarray(i)                  # works fine                                                 

Now try with unacceptable type:
i=np.zeros((100,100,4),dtype=np.int16) 
print(i.dtype)                           # prints dtype('int16')                                                   

im = Image.fromarray(i) 
TypeError: Cannot handle this data type

So, the answer is that your underlying datatype is unacceptable. Check it with v.dtype.

