1

I'm trying to make a 2D array of Strings using the ndarray crate..

    use ndarray::Array2;
    char_array = Array2::<String>::zeros((width, height));

Clearly, it doesn't work, so what's the equivalent of zeroes for initialising a String type array?

I've managed to get a work-around using:

    use ndarray::Array;
    let mut char_array = Array::from_elem((width,height),NEW_STR);

but it feels like there should be a better (proper) way?

1 Answer 1

5

You can use the default construction of Array2.

let char_array: Array2<String> = Array2::default((width, height));
Sign up to request clarification or add additional context in comments.

1 Comment

that works nicely! thanks so much fdan. I figured it had to be simple!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.