iwanakatana
iwanakatana

Reputation: 13

Structuring data in this multidimensional-array

I am processing images in python and for a specific purpose I've been asked to "make numpy arrays with these dimensions: 32x3x512x512 (patches x color channels, height, width)." I don't have any problem getting any of the data, but I just cannot picture the structure of the numpy array. My best approaches are: Option 1, Option 2 . And I may be not even close.

Any better idea on how the numpy array should look?

Upvotes: 1

Views: 24

Answers (1)

John Zwinck
John Zwinck

Reputation: 249123

You can literally take the problem description and use it as the shape of the array:

arr = np.empty((32, 3, 512, 512), 'u1')

Now arr[0] is the first patch (i.e. first image), and has the shape (3, 512, 512), so it's 24 (3x8) bits per pixel, and the dimensions are 512 x 512 pixels.

Some people might use a different ordering of the dimensions, such as (32, 512, 512, 3), but it really depends on the processing you eventually want to do.

Upvotes: 1

Related Questions