Multidimensional array

  1. consider a multidimensional array
    let array1:[[usize;50];50]=[[0;50];50];
    how will i find the length of row and col of that array separately using len()
    is it possible ?
  2. how to slice a multidimensional array
    row and col according to our need ?

Generally you use a crate that makes this easier to deal with, such as

without using ndarray

For multidimensional arrays, you are often better served by implementing them with an underlying 1-dimensional array/vector and providing appropriate indexing and slicing operations. For each dimension you just need to remember the associated offset and stride, which will be modified/used by slicing and indexing operations.

1 Like

i just wand to slice a 2d array according to the row and col input by user without using ndarray or any other packages

can you show an example

What do you want to get out of the slicing operation? An owned array? (in which case you need to know the slicing indices at compile time), or a “view” into the data provided by the user without copying the underlying data, or a dynamically sized but owned copy of the data?

any other option

A slice-able view into the data could look somewhat like this:

A slice is a contiguous memory chunk which consists of zero or more values of same types, that placed directly next to each other. Using only array-of-array storage, how can you represent your result as slice which is sliced by both row and column? Say you have 50*50 2d array, and want to slice them as 40*40 slice. Then your resulting slice’s rows are not placed directly each other, instead they have 10-elem wide paddings between each of them.