VansFannel
VansFannel

Reputation: 45921

Understanding numpy shape

I'm newbie with Python and also with Numpy.

I have this code:

one_array.shape

When I run it, I get this output:

(20, 48, 240, 240)

one_array is a Numpy Array that has 20 images.

What do mean the other three numbers in shape output (48, 240, 240)?

Upvotes: 1

Views: 255

Answers (4)

David
David

Reputation: 8298

Your array consist of 20 images, each of them is the size 48X240X240. Which is odd, I would expect that it will be something like 240X240X3 but for some reason you have way more channels (referring to RGB). ]

So the shape function return the size of dimension along each axis (the current shape of the entire array), so in your case there is (20, 48, 240, 240)

Edit:

As the user said, each image consist of 48 NITFY images of 1 channel which explain the output of shape

Upvotes: 2

Diego Palacios
Diego Palacios

Reputation: 1144

You are right, you can think of one_array as an array with 20 elements, in which is element in another array with shape (48, 240, 240). However, usually is it better to think that one_array is a 4 dimensional array, that has a total of 20x48x240x240 = 55296000 elements.

Upvotes: 0

9mat
9mat

Reputation: 1234

one_array.shape == (20, 48, 240, 240) means that one_array is a 4-dimensional array with 20*48*240*240 or 55296000 elements.

Upvotes: 0

Phoenixo
Phoenixo

Reputation: 2113

Imagine your Numpy Array as a Vector that can be in one dimension, but in your case it looks like it is in dimension 4. (20, 4, 240, 240) means a big matrix composed of 20 x 4 x 240 x 240 elements.

Upvotes: 0

Related Questions