Got an ArrayD which always has 2 dimensions, but is an ArrayD due to a calculation, need to change this to Array2 for storage.
Been looking through documentation, can't seem to find a way.
Is there a function to do it?
Got an ArrayD which always has 2 dimensions, but is an ArrayD due to a calculation, need to change this to Array2 for storage.
Been looking through documentation, can't seem to find a way.
Is there a function to do it?
If you have a variable of type ArrayD<f32>, you can do:
// convert n-dimensional array into 2d array
let arr2d: Array2<f32> = arr2d.into_dimensionality::<Ix2>()?;
to convert it into a variable of type Array2<f32>.
If the dimensions don't match, it will throw an ndarray::ShapeError error.