get_num_dims#

ivy.get_num_dims(x, /, *, as_array=False)[source]#

Return the number of dimensions of the array x.

Parameters:
  • x (Union[Array, NativeArray]) – Input array to infer the number of dimensions for.

  • as_array (bool, default: False) – Whether to return the shape as a array, default False.

Return type:

int

Returns:

  • ret – Shape 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.get_num_dims(a, as_array=False)
>>> print(b)
3

With ivy.Container input:

>>> a = ivy.Container(b = ivy.asarray([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]]))
>>> print(ivy.get_num_dims(a))
{
    b: 2
}
>>> b = ivy.get_num_dims(a, as_array=True)
>>> print(b)
{
    b: ivy.array(2)
}
Array.get_num_dims(self, /, *, as_array=False)[source]#

ivy.Array instance method variant of ivy.shape. This method simply wraps the function, and so the docstring for ivy.shape also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array to infer the number of dimensions for

  • as_array (bool, default: False) – Whether to return the shape as a array, default False.

Return type:

int

Returns:

ret – Shape of the array

Examples

>>> x = ivy.array([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]])
>>> b = x.get_num_dims()
>>> print(b)
2
>>> x = 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 = x.get_num_dims(as_array=False)
>>> print(b)
3
>>> b = x.get_num_dims(as_array=True)
>>> print(b)
ivy.array(3)
Container.get_num_dims(self, /, *, as_array=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

ivy.Container instance method variant of ivy.get_num_dims. This method simply wraps the function, and so the docstring for ivy.get_num_dims also applies to this method with minimal changes.

Parameters:
  • self (Container) – ivy.Container to infer the number of dimensions for

  • as_array (Union[bool, Container], default: False) – Whether to return the shape as a array, default False.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

Return type:

Container

Returns:

ret – Shape of the array

Examples

>>> a = ivy.Container(b = ivy.asarray([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]]))
>>> a.get_num_dims()
{
    b: 2
}
>>> 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.get_num_dims()
{
    b: 3
}
>>> 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.get_num_dims()
{
    b: 3,
    c: 2
}
>>> a.get_num_dims(as_array=True)
{
    b: ivy.array(3),
    c: ivy.array(2)
}