Comment on page
tensor.reduce_sum_square
fn reduce_sum_square(self: @Tensor<T>, axis: usize, keepdims: bool) -> Tensor<T>;
Computes the sum square of the input tensor's elements along the provided axes.
self
(@Tensor<T>
) - The input tensor.axis
(usize
) - The dimension to reduce.keepdims
(bool
) - If true, retains reduced dimensions with length 1.
- Panics if axis is not in the range of the input tensor's dimensions.
A new
Tensor<T>
instance with the specified axis reduced by summing its elements.fn reduce_sum_square_example() -> Tensor {
let mut shape = ArrayTrait::<usize>::new();
shape.append(2);
shape.append(2);
let mut data = ArrayTrait::new();
data.append(1);
data.append(2);
data.append(3);
data.append(4);
let tensor = TensorTrait::<u32>::new(shape.span(), data.span());
We can call `reduce_sum_square` function as follows.
return tensor.reduce_sum_square(axis: 1, keepdims: true);
}
[[5, 25]]
Last modified 20d ago