Reputation: 2723
Is there a fast way to stack images into a cube? I know that you can use np.append to append two, but if there is a lot of them then you need a forloop and a reshape. are there any smarter ways to do it?
Upvotes: 0
Views: 459
Reputation: 2656
You can use np.stack
which takes an arbitrary number of arrays an concatenates them along a new axis.
Example:
images = [np.random.randn(8, 12) for _ in range(50)]
stacked = np.stack(images, axis=0)
print(stacked.shape) # output: (50, 8, 12)
Upvotes: 4