Issue
I have 2 2D numpy arrays with shape (160000,91)
.
160000
means all pixels of an image (200x800)
, 91
means # of images.
U(160000,91)
and V(160000,91).
How to create a numpy array X
with shape (91,200,800,2)
with X(:,:,:,0)
= U(91,200,800)
and X(:,:,:,1) = V(91,200,800)
?
Solution
Transpose to move the batch dimension to axis 0. Then reshape the two arrays and stack them along a new axis 3:
import numpy as np
U = np.random.random((160000, 91))
V = np.random.random((160000, 91))
X = np.stack((np.reshape(U.T, (-1, 200, 800)),
np.reshape(V.T, (-1, 200, 800))),
axis=3)
print(X.shape) # (91, 200, 800, 2)
Answered By - asdf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.