- consider a multidimensional array
how will i find the length of row and col of that array separately using len()
is it possible ?
- 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 https://docs.rs/ndarray/0.12.1/ndarray/struct.ArrayBase.html
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.
i just wand to slice a 2d array according to the row and col input by user without using ndarray or any other crates.io 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: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ee3c71a380aa2373460e4c6ee25f1985
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.