Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy: "size" vs. "shape" in function arguments?

Tags:

python

numpy

I noticed that some numpy operations take an argument called shape, such as np.zeros, whereas some others take an argument called size, such as np.random.randint. To me, those arguments have the same function and the fact that they have different names is a bit confusing. Actually, size seems a bit off since it really specifies the .shape of the output.

Is there a reason for having different names, do they convey a different meaning even though they both end up being equal to the .shape of the output?

like image 942
P-Gn Avatar asked Jun 28 '17 14:06

P-Gn


1 Answers

Shape relates to the size of the dimensions of an N-dimensional array.

Size regarding arrays, relates to the amount (or count) of elements that are contained in the array (or sometimes, at the top dimension of the array - when used as length).

For example, let a be a matrix

1  2  3  4
5  6  7  8
9 10 11 12

the shape of a is (3, 4), the size of a is 12 and the size of a[1] is 4.

like image 184
Uriel Avatar answered Oct 03 '22 03:10

Uriel