I\'m trying to populate an array by using 2D arrays with np.dstack.
m1 = np.array([[1,1],[1,1]]) m2 = np.array([[2,2],[2,2]]) m3 = np.array([[3,3],[3,3]])
There is no need to do this in a for loop, you can add a variable number of matrices in the tuple you pass to np.dstack, like:
for
np.dstack
>>> np.dstack((m1, m2, m3)) array([[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3]]])