ztcl::tensor slice
Copies a box of a tensor.
ztcl::tensor slice TENSOR ?SPEC ...?
Description
Gives a copy of a box of TENSOR. Each SPEC is for one leading axis: * is the whole axis, a list {FIRST LAST} is a range with both ends in it, and one index removes the axis. An index can be end, end-N, or end+N. An axis with no SPEC is whole.
Returns
A tensor.
Examples
Each example of this page runs after package require ztcl::tensor.
% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor slice $a * {1 2}
tensor f32 {2 2} {2.0 3.0 5.0 6.0}
% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor slice $a 1
tensor f32 3 {4.0 5.0 6.0}
% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor slice $a end end-1
tensor f32 {} 5.0
Errors
% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor slice $a 2
tensor slice: range "2" is outside axis 0 of size 2
-errorcode ZTCL TENSOR
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.4
- Compute cost
- A cost for each element operation by its kind (a copy, an add, a division, a math function, a multiply-add of a matmul), set so that one compute unit takes about the time of one unit of plain Tcl. docs/modules/tensor.md has the table.