@@ -24,42 +24,11 @@ Rust bindings for the NumPy C-API.
2424
2525## Example
2626
27- ### Execute a Python program from Rust and get results
28-
29- ``` toml
30- [package ]
31- name = " numpy-test"
32-
33- [dependencies ]
34- pyo3 = { version = " 0.15" , features = [" auto-initialize" ] }
35- numpy = " 0.15"
36- ```
37-
38- ``` rust
39- use numpy :: PyArray1 ;
40- use pyo3 :: prelude :: {PyResult , Python };
41- use pyo3 :: types :: IntoPyDict ;
42-
43- fn main () -> PyResult <()> {
44- Python :: with_gil (| py | {
45- let np = py . import (" numpy" )? ;
46- let locals = [(" np" , np )]. into_py_dict (py );
47- let pyarray : & PyArray1 <i32 > = py
48- . eval (" np.absolute(np.array([-1, -2, -3], dtype='int32'))" , Some (locals ), None )?
49- . extract ()? ;
50- let readonly = pyarray . readonly ();
51- let slice = readonly . as_slice ()? ;
52- assert_eq! (slice , & [1 , 2 , 3 ]);
53- Ok (())
54- })
55- }
56-
57- ```
58-
5927### Write a Python module in Rust
6028
6129Please see the [ simple-extension] ( https://github.com/PyO3/rust-numpy/tree/main/examples/simple-extension )
6230directory for the complete example.
31+
6332Also, we have an example project with [ ndarray-linalg] ( https://github.com/PyO3/rust-numpy/tree/main/examples/linalg ) .
6433
6534``` toml
@@ -114,6 +83,38 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
11483}
11584```
11685
86+ ### Execute a Python program from Rust and get results
87+
88+ ``` toml
89+ [package ]
90+ name = " numpy-test"
91+
92+ [dependencies ]
93+ pyo3 = { version = " 0.15" , features = [" auto-initialize" ] }
94+ numpy = " 0.15"
95+ ```
96+
97+ ``` rust
98+ use numpy :: PyArray1 ;
99+ use pyo3 :: prelude :: {PyResult , Python };
100+ use pyo3 :: types :: IntoPyDict ;
101+
102+ fn main () -> PyResult <()> {
103+ Python :: with_gil (| py | {
104+ let np = py . import (" numpy" )? ;
105+ let locals = [(" np" , np )]. into_py_dict (py );
106+ let pyarray : & PyArray1 <i32 > = py
107+ . eval (" np.absolute(np.array([-1, -2, -3], dtype='int32'))" , Some (locals ), None )?
108+ . extract ()? ;
109+ let readonly = pyarray . readonly ();
110+ let slice = readonly . as_slice ()? ;
111+ assert_eq! (slice , & [1 , 2 , 3 ]);
112+ Ok (())
113+ })
114+ }
115+
116+ ```
117+
117118## Dependency on ndarray
118119
119120This crate uses types from ` ndarray ` in its public API. ` ndarray ` is re-exported
@@ -141,6 +142,7 @@ cargo update ---package ndarray:0.15.3 --precise 0.13.1
141142to achieve a single dependency on version ` 0.13.1 ` of ` ndarray ` .
142143
143144## Contributing
145+
144146We welcome [ issues] ( https://github.com/PyO3/rust-numpy/issues )
145147and [ pull requests] ( https://github.com/PyO3/rust-numpy/pulls ) .
146148
0 commit comments