mygrad.Tensor.base#
- property Tensor.base: Tensor | None#
A reference to the base tensor that the present tensor is a view of.
It this tensor owns its memory, then this returns
None
.Examples
The base of a tensor that owns its memory is
None
:>>> import mygrad as mg >>> x = mg.arange(5) >>> x.base is None True
Slicing creates a view, whose memory is shared with x:
>>> y = x[2:] >>> y.base is x True >>> y.data.base is x.data True
A view of a view has the same base as its “parent”
>>> z = y[:] >>> z.base is x True
The behavior of
Tensor.base
departs from that ofndarray.base
in that mygrad will never create an “internal” tensor to serve as a base; e.g.>>> import numpy as np >>> np.reshape(2., (1,)).base array(2.)
>>> mg.reshape(2., (1,)).base is None True