python_student
python_student

Reputation: 65

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?

Upvotes: 1

Views: 84

Answers (1)

sharathnatraj
sharathnatraj

Reputation: 1614

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)

Upvotes: 1

Related Questions