我有一个 3D NumPy 数组 (2700, 4000, 2),我想将它转换为两个不同的 2D 数组。我的意思是,我的两个新数组将是 (2700,4000)。
我是 Python 编程的新手。有没有办法做到这一点?
答案 0 :(得分:1)
IIUC,给你。
代码
#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)
输出
Original Shape : (2700, 4000, 2)
First array shape : (2700, 4000)
Second array shape : (2700, 4000)