mygrad.Tensor.shape#

property Tensor.shape: Shape#

Tuple of tensor dimension-sizes.

Sizes are reported in row-major order.

Returns:
Tuple[int, …]

See also

mygrad.reshape

similar function

Tensor.reshape

similar method

Examples

>>> import mygrad as mg
>>> x = mg.Tensor([1, 2, 3, 4])  # axis-0 has size 4
>>> x.shape
(4,)
>>> y = mg.Tensor([[1, 2, 3],    # axis-0 has size 2, axis-1 has size 3
...                [4, 5, 6]])
>>> y.shape
(2, 3)

The shape attribute can also be set to reshape the tensor in-place

>>> y.shape = (1, 6, 1)
>>> y
Tensor([[[1],
         [2],
         [3],
         [4],
         [5],
         [6]]])