0

I have generated a numpy array from an existing raster in ArcGIS using RasterToNumPyArray, but when it is imported the array shape is (bands,rows,columns) and I need to convert to (rows,columns,bands). However, I can't quite figure out how to do it.

Here is an example, with a toy raster with 5 bands and 10x10 cells:

old = np.arange(500).reshape(5,10,10)
new = old.reshape((10,10,5))

band1 would have values from 0:99 (old[0,:,:]. However, new[:,:,0] is not the same. I just can't quite figure it out.

1 Answer 1

0

I figured it out. It might not be the best way, but here is the example I came up with.

I used a different starting array.

a = np.repeat(1,25)
b = np.repeat(2,25)
c = np.arange(25)
arr = np.concatenate((a,b,c))
arr = arr.reshape(3,5,5)
arr = arr.reshape(3,25)
arr = arr.transpose()

Results in

array([[ 1,  2,  0],
       [ 1,  2,  1],
       [ 1,  2,  2],
       ...
       [ 1,  2, 23],
       [ 1,  2, 24]])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.