简体   繁体   中英

3D NumPy array to 2D and getting two different 2D array from a 3D array

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM