forked from sbu-python-class/python-science
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
34 lines (24 loc) · 819 Bytes
/
README
File metadata and controls
34 lines (24 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
This example for using the C-API with NumPy is for python 3.x only --
the interface for python 2.x is different. Note that this was written
to use the latest API.
reference: http://scipy-lectures.github.io/advanced/interfacing_with_c/interfacing_with_c.html
http://wiki.scipy.org/Cookbook/C_Extensions/NumPy_arrays
to build:
python3 setup.py build_ext --inplace
to run:
>>> import numpy_in_c
>>> help (numpy_in_c)
>>> import numpy as np
>>> a = np.arange(20, dtype=np.float64)
>>> a.shape = (4,5)
>>> print a
[[ 0. 1. 2. 3. 4.]
[ 5. 6. 7. 8. 9.]
[ 10. 11. 12. 13. 14.]
[ 15. 16. 17. 18. 19.]]
>>> b = numpy_in_c.example(a)
>>> print b
[[ 0. 1. 4. 9. 16.]
[ 25. 36. 49. 64. 81.]
[ 100. 121. 144. 169. 196.]
[ 225. 256. 289. 324. 361.]]