-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ndarray equivalent of numpy.astype? #493
Comments
A safe way to perform the conversion is For your specific use-case (getting an array of |
By the way, depending on what you're trying to do, you may also be interested in |
Thanks for the response; we will try mapv out tomorrow. I was expecting a copy anyway since usize is 64 bit on our current target, but maybe the view pyarray returns will work with mapv. Thanks also for the recommendation for ndarray-npy; with a rapidly evolving ecosystem recommendations for what works are always valuable! |
Yeah, if the new element type is larger than the old element type, you won't be able to avoid a copy. |
How does one convert the type of an array? We're trying to go from an owned
Array2<u32>
to an ownedArray2<usize>
.We've tried to_owned(), into_owned(), and from(), and can't find anything that works. Do we need to resort to iterators for this?
As a documentation feature request, could you please add the answer to the "ndarray_for_numpy_users" page?
The wider context is that we're trying to get our data out of python using the rust-numpy crate:
https://github.com/rust-numpy/rust-numpy
but their example doesn't get the data all the way into an owned ndarray; it's still a view into a custom type wrapping data that is still owned by a python interpreter.
It already took us hours to get this far:
I'm hoping you can get us the rest of the way there, or maybe even point us to a conversion path that only incurs one copy rather than two...
The text was updated successfully, but these errors were encountered: