mygrad.ravel#

mygrad.ravel(a: ArrayLike, *, constant: Optional[bool] = None) Tensor[source]#

Flattens contents of a tensor into a contiguous 1-D array. A copy is made only if needed.

This docstring was adapted from numpy.ravel.

Parameters
aArrayLike

The tensor to be flattened

constantbool, optional(default=False)

If True, the returned tensor is a constant (it does not back-propagate a gradient)

Returns
mygrad.Tensor

Notes

ravel utilizes C-ordering, meaning that it reads & writes elements using C-like index ordering; the last axis index changing fastest, and, proceeding in reverse order, the first axis index changing slowest.

Examples

>>> import mygrad as mg
>>> x = mg.Tensor([[1, 2],
...                [3, 4]])
>>> mg.ravel(x)
Tensor([1, 2, 3, 4])