Burn Core: burn::tensor::Tensor::reshape
The Tensor::reshape method returns a tensor with a new dimensional layout while preserving the same logical number of elements. The main parameter is the target shape. The product of the new dimensions must match the product of the original dimensions.
This method changes the tensor view or layout representation but does not define a mathematical transformation such as matrix multiplication or convolution. It is typically used before flattening a batch, preparing attention heads, or converting a multi-dimensional activation.
Parameters
| Parameter Name | Type | Description |
|---|---|---|
self |
Tensor<B, D> |
The source tensor whose element count must be preserved. |
shape |
Shape | array |
The target shape requested for the returned tensor. |
let device = B::Device::default();
let x = Tensor::<B, 3>::ones([2, 3, 4], &device);
let y = x.reshape([2, 12]);
println!("{y}");
Example Output
{
"status": "success",
"operation": "reshape",
"input_shape": [2, 3, 4],
"output_shape": [2, 12]
}