Skip to main content

tensor4d_slice

Function tensor4d_slice 

Source
pub fn tensor4d_slice(
    tensor: &ArrayBase<OwnedRepr<f32>, Dim<[usize; 4]>>,
    index: usize,
) -> Result<ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>, OCRError>
Expand description

Extracts a 3D slice from a 4D tensor at the specified index.

§Arguments

  • tensor - A reference to a 4D tensor.
  • index - The index of the slice to extract.

§Returns

  • Ok(Tensor3D) - A 3D tensor slice extracted from the input tensor.
  • Err(OCRError) - An error if the index is out of bounds.

§Examples

use oar_ocr_core::utils::tensor::{tensor4d_slice, vec_to_tensor4d};
// Create a tensor first
let data = vec![vec![vec![vec![1.0, 2.0], vec![3.0, 4.0]]]];
let tensor = vec_to_tensor4d(&data)?;
let slice = tensor4d_slice(&tensor, 0)?;