summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/numpy
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2021-11-02 09:57:05 +0000
committerGitHub <noreply@github.com>2021-11-02 10:57:05 +0100
commit00ffb022f82cf13a055102288ca5c1b299f4ecdc (patch)
tree4a164e3e4908cab33feec7b3ff82e5873f112ee2 /docs/examples/tutorial/numpy
parentc69992aa4eb0f7b4529f776820d20b8c66486972 (diff)
downloadcython-00ffb022f82cf13a055102288ca5c1b299f4ecdc.tar.gz
Add "import_array()" to the Numpy tutorial (GH-4403)
Arguably, it's unnecessary if the auto-call works correctly, but if we're still advising users to do it themselves then it probably should be in the docs.
Diffstat (limited to 'docs/examples/tutorial/numpy')
-rw-r--r--docs/examples/tutorial/numpy/convolve2.pyx6
1 files changed, 6 insertions, 0 deletions
diff --git a/docs/examples/tutorial/numpy/convolve2.pyx b/docs/examples/tutorial/numpy/convolve2.pyx
index c122aeb3c..b77b92f53 100644
--- a/docs/examples/tutorial/numpy/convolve2.pyx
+++ b/docs/examples/tutorial/numpy/convolve2.pyx
@@ -9,6 +9,12 @@ import numpy as np
# currently part of the Cython distribution).
cimport numpy as np
+# It's necessary to call "import_array" if you use any part of the
+# numpy PyArray_* API. From Cython 3, accessing attributes like
+# ".shape" on a typed Numpy array use this API. Therefore we recommend
+# always calling "import_array" whenever you "cimport numpy"
+np.import_array()
+
# We now need to fix a datatype for our arrays. I've used the variable
# DTYPE for this, which is assigned to the usual NumPy runtime
# type info object.