rustrust-ndarray

How do you turn an ndarray::ArrayView into a new ndarray?


How do you efficiently take a view of an ndarray and create a new ndarray from it, like array[1..5, 3..6]?


Solution

  • The docs of ArrayBase have a nice conversion table. The way to convert from ArrayView and ArrayViewMut to Array is view.to_owned().

    To slice an owned array into an owned array, though, have a more efficient implementation: slice_move() or slice_collapse().