Manipulating Tensors
Tensors

Prev:Creating Tensors


The number of dimensions can be extracted with:
dims ( tensor -- n )


Tensors can be reshaped with:
reshape ( tensor shape -- tensor )

flatten ( tensor -- tensor )


Tensors can be combined element-wise with other tensors as well as numbers with:
t+ ( x y -- tensor )

t- ( x y -- tensor )

t* ( x y -- tensor )

t/ ( x y -- tensor )

t% ( x y -- tensor )


Tensors support the following matrix operations:
matmul ( tensor1: tensor tensor2: tensor -- tensor3: tensor )

transpose ( tensor: tensor -- tensor': tensor )


Tensors also support the following concatenation operations:
stack ( seq -- tensor )

hstack ( seq -- tensor )

vstack ( seq -- tensor )

t-concat ( seq -- tensor )


Tensors implement all sequences operations.

Tensors can be indexed into using either numbers or arrays, for example:
USING: prettyprint sequences tensors ; t{ { 0.0 1.0 2.0 } { 3.0 4.0 5.0 } } [ { 1 1 } swap nth ] [ 4 swap nth ] bi = .
t

If the array being used to index into the tensor has the wrong number of dimensions, a dimension-mismatch-error will be thrown.