I have an array (Numpy of shape (100, 256, 256). How can I change this to (100, 256, 256,3)? I tried doing reshape but it doesn't work, Can anyone help me.
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – radouxju, Kersten, nmtoken, ArMoraer, xunilk
It's impossible to do this kind of reshape [(100, 256, 256) -> (100, 256, 256,3)]. It's only possible a compatible reshape. This is an example:
>>>import numpy as np >>>list = range(100*256*256) >>>array = np.reshape(list, (100, 256, 256)) >>>array = np.reshape(list, (100, 256, 256, 3)) #your reshape: I got an error! Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/numpy-1.11.0-py2.7-linux-i686.egg/numpy/core/fromnumeric.py", line 224, in reshape return _wrapit(a, 'reshape', newshape, order=order) File "/usr/local/lib/python2.7/dist-packages/numpy-1.11.0-py2.7-linux-i686.egg/numpy/core/fromnumeric.py", line 48, in _wrapit result = getattr(asarray(obj), method)(*args, **kwds) ValueError: total size of new array must be unchanged >>>array = np.reshape(list, (10, 256, 256, 10)) # compatible reshape: no error