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.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Jul 8, 2022 at 18:54

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]])
answered Jul 11, 2022 at 15:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.