Commit 6a3fc36c authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2429 from gabrieldemarmiesse/test_memoryviews_2

Added tests for "typed memoryviews" part 2
parents b260846e 693be012
import numpy as np
def add_one(int[:,:] buf):
for x in range(buf.shape[0]):
for y in range(buf.shape[1]):
buf[x, y] += 1
# exporting_object must be a Python object
# implementing the buffer interface, e.g. a numpy array.
exporting_object = np.zeros((10, 20), dtype=np.intc)
add_one(exporting_object)
...@@ -97,12 +97,9 @@ dimension:: ...@@ -97,12 +97,9 @@ dimension::
print(buf[-1,-2]) print(buf[-1,-2])
The following function loops over each dimension of a 2D array and The following function loops over each dimension of a 2D array and
adds 1 to each item:: adds 1 to each item:
def add_one(int[:,:] buf): .. literalinclude:: ../../examples/userguide/memoryviews/add_one.pyx
for x in xrange(buf.shape[0]):
for y in xrange(buf.shape[1]):
buf[x,y] += 1
Indexing and slicing can be done with or without the GIL. It basically works Indexing and slicing can be done with or without the GIL. It basically works
like NumPy. If indices are specified for every dimension you will get an element like NumPy. If indices are specified for every dimension you will get an element
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment