tensor.sign
fn sign(self: @Tensor<T>) -> Tensor<T>;
Calculates the sign of the given input tensor element-wise. If input > 0, output 1. if input < 0, output -1. if input == 0, output 0.
Args
self
(@Tensor<T>
) - Tensor of data to calculates the sign of the given input tensor element-wise.
Returns
A new Tensor<T>
of the same shape as the input tensor with The sign of the input tensor computed element-wise.
Example
use core::array::{ArrayTrait, SpanTrait};
use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor};
fn sign_example() -> Tensor<i32> {
let tensor = TensorTrait::<i32>::new(
shape: array![11].span(),
data: array![-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5].span(),
);
return tensor.sign();
}
>>> [-1, -1, -1, -1, -1, 0, 1, 1, 1, 1, 1]
Last updated
Was this helpful?