-
Notifications
You must be signed in to change notification settings - Fork 7
Tensor
Most important to read: The Tensor interface
The float64
and string
types have special access methods because any number can be represented by the float, and anything at all can be represented by a string.
There are also separate methods for accessing via a 1D
index vs. the full high-dimensional set of indexes. Shape.Offset()
method computes a 1D
index from a full set of indexes. Using the 1D index is always faster.
The next most important thing to know about tensors is the Shape type, which determines the number and size of each dimension.
Use SetShape
to set the shape of an existing tensor to something else -- this is data preserving and can be very handy for e.g., turning a higher-dimensional tensor into a lower-dimensional one that can then be processed e.g., by the gonum
matrix functions.
The SubSpace
function is also very useful, for getting a new Tensor view of a lower-dimensional subspace of the full tensor. This is for example how a single row of a Table
can be accessed as a Tensor.
If you know the concrete type of a tensor, directly accessing its Values
slice is the most efficient.