Skip to content

[Basic Question] What is the difference in usage between numpy and ndarray key crates? #387

Answered by adamreichold
rkshthrmsh asked this question in Q&A
Discussion options

You must be logged in to vote

This crate integrates NumPy and ndarray and it is used to implement Python extensions using the PyO3 bindings which provide their Python API in terms of NumPy types but internally work on these arrays using ndarray.

The key functionality to enable this is that your #[pyfunction] can take for example a PyReadonlyArray2<f64> to reference the NumPy array passed in on the Python side and use PyReadonlyArray::as_array to turn this into a ArrayView2<f64> without copying the underlying data which you can operate on using the functionality provided by ndarray.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by rkshthrmsh
Comment options

You must be logged in to vote
1 reply
@adamreichold
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants