sodiumnitrate
sodiumnitrate

Reputation: 3131

Reordering numpy array indices

I have a 2D array that I want to create an image from. I want to transform the image array of dimensions 140x120 to an array of 140x120x3 by stacking the same array 3 times (to get a grayscale image to use with skimage).

I tried the following:

image = np.uint8([image, image, image])

which results in a 3x120x140 image. How can I reorder the array to get 120x140x3 instead?

Upvotes: 1

Views: 188

Answers (1)

mtrw
mtrw

Reputation: 35088

np.dstack([image, image, image]) (docs) will return an array of the desired shape, but whether this has the right semantics for your application depends on your image generation library.

Upvotes: 1

Related Questions