Commit 693be012 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moving an example from memoryviews.rst to the examples directory.

parent 084a25f5
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)
......@@ -102,12 +102,9 @@ dimension::
print(buf[-1,-2])
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):
for x in xrange(buf.shape[0]):
for y in xrange(buf.shape[1]):
buf[x,y] += 1
.. literalinclude:: ../../examples/userguide/memoryviews/add_one.pyx
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
......
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