Reputation: 5486
Suppose there is an array
(1) x=np.array([[1,2],[1,2],[1,2]])
and a second array
(2) y=np.array([[1],[1,2],[1,2,3]])
The command size(x)
returns the total count of all elements along every axis. In this case 6
. However, size(y)
returns 3
. This must be because numpy interprets (2) in this case as three elements (the three subarrays) along one axis, although shape(y)
returns (3, )
. My question is now: how can I get numpy to interpret (2) as an array with three axes, so that size(y)
returns the total count of all atomic elemets, which is 6
?
Upvotes: 0
Views: 617
Reputation: 1546
I don't think it's possible to get the number of elements from y
without looping over the objects.
The problem is that the elements of y
are not numbers, they are objects (lists). Numpy does not support lists of lists and therefore it stores it as a 1-dimensional array of objects. I don't think there are Numpy methods to get the total number of elements in y
.
Upvotes: 1