mygrad.Tensor.null_grad#
- Tensor.null_grad(*, _clear_view_info: bool = False) Tensor [source]#
Sets this tensor’s gradient to be
None
.This operation is performed in-place, but a reference to the tensor is returned in order to permit mapping semantics.
Also removes any
base
reference from disconnected views.- Returns:
- self
Examples
>>> import mygrad as mg >>> x = mg.Tensor(2.) >>> (x ** 2).backward() >>> x.grad array(4.) >>> x.null_grad() # returns a reference of `x` Tensor(2.0) >>> x.grad is None True