beetlebug▾
/

ztcl::tensor onehot

Makes the one-hot rows of a list of classes.

ztcl::tensor onehot INDEX CLASSES ?DTYPE?

Description

Gives a matrix with a row for each element of INDEX and CLASSES columns, with 1 at the column of the class and 0 in the others. The default dtype is f32.

Returns

A tensor.

Examples

Each example of this page runs after package require ztcl::tensor.

% ztcl::tensor onehot {1 0} 3 i32
tensor i32 {2 3} {0 1 0 1 0 0}

Errors

% ztcl::tensor onehot {5} 3
tensor onehot: index out of range
-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.