mygrad.Tensor.ndim#

property Tensor.ndim: int#

Number of tensor dimensions. I.e. the number of indices that must be supplied to uniquely specify an element in the tensor.

Returns:
int

Examples

>>> import mygrad as mg
>>> x = mg.Tensor([1, 2, 3])
>>> x.ndim
1
>>> x[0]  # a single index identifies an element in `x`
Tensor(1)
>>> y = mg.Tensor([[1, 2, 3],
...                [4, 5, 6]])
>>> y.ndim
2
>>> y[0, 0]  # two indices are required to identify an element in `x`
Tensor(1)