1

I have a 3D NumPy array (2700, 4000, 2) and I want to convert it two different 2D array. I mean, my new two arrays will be (2700,4000).

I am new at Python programming. Is there any way to do this?

1
  • Assuming you meant to say 2 (2700, 4000) arrays. It might help if you explain why you'd prefer two 2D arrays.
    – Kraigolas
    Commented May 24, 2021 at 2:05

1 Answer 1

1

IIUC, here you go.

Code

#Define the 3D array
n1 = np.ones((2700,4000,2))
#Get the first 2D array
n2 = n1[:,:,0]
#Get the second 2D array
n3 = n1[:,:,1]
print("Original Shape : ", n1.shape)
print("First array shape : ", n2.shape)
print("Second array shape : ", n3.shape) 

Output

Original Shape :  (2700, 4000, 2)
First array shape :  (2700, 4000)
Second array shape :  (2700, 4000)

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.