mygrad.Tensor.copy#

Tensor.copy(*, constant: Optional[bool] = None) Tensor[source]#

Produces a copy of self with copy.creator=None.

Copies of the underlying numpy data array and gradient array are created.

No information regarding the tensor’s participation in the computational graph are copied.

Parameters
constantOptional[bool]
Returns
Tensor

Examples

>>> import mygrad as mg
>>> x = mg.Tensor(data, constant=constant)
>>> y = x * 2
>>> y.backward()
>>> y_copy = y.copy()
>>> y_copy
Tensor(6)
>>> y_copy.grad
array(1.)
>>> y_copy.creator is None
True