'replace one floor of a 3D np array by a 2D numpy array
I'm trying to "replace one floor of a 3D np array by a 2D numpy array"
this is my code, but I'm pretty sure there is a better way :
import numpy as np
w,h = 2,5
board_2D = np.random.randint(1, 5, size=(h, w))
board_3D = np.arange(h*w*4).reshape(4,h,w)
print(board_3D)
z= 1
for y in range(h):
for x in range(w):
board_3D[z,y,x] = board_2D[y,x]
print(board_3D)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
