size#
- ivy.size(x)[source]#
Return the number of elements of the array x.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array to infer the number of elements for.- Return type:
int
- Returns:
ret – Number of elements of the array
Both the description and the type hints above assumes an array input for simplicity,
but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.
Examples
With
ivy.Array
input:>>> a = ivy.array([[[0, 0, 0], [0, 0, 0], [0, 0, 0]], ... [[0, 0, 0], [0, 0, 0], [0, 0, 0]], ... [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]) >>> b = ivy.size(a) >>> print(b) 27
With
ivy.Container
input:>>> a = ivy.Container(b = ivy.asarray([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]])) >>> print(ivy.size(a)) { b: 9 }
- Array.size()#
Number of elements in the array.
- Container.size(self, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.size. This method simply wraps the function, and so the docstring for ivy.size also applies to this method with minimal changes.
- Parameters:
self (
Container
) – ivy.Container to infer the number of elements forkey_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
ret – Number of elements of the array
Examples
>>> a = ivy.Container(b = ivy.asarray([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]])) >>> a.size() { b: 9 } >>> a = ivy.Container(b = ivy.array([[[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]]])) >>> a.size() { b: 27 } >>> a = ivy.Container(b = ivy.array([[[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]]]), ... c = ivy.asarray([[0.,1.,1.],[8.,2.,3.]])) >>> a.size() { b: 18, c: 6, }