Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
61d52da9
Commit
61d52da9
authored
Jun 21, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
section on array.array in memoryview docs
parent
e65460b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
docs/src/userguide/memoryviews.rst
docs/src/userguide/memoryviews.rst
+29
-0
No files found.
docs/src/userguide/memoryviews.rst
View file @
61d52da9
...
@@ -535,6 +535,35 @@ may be assigned directly to a memoryview slice::
...
@@ -535,6 +535,35 @@ may be assigned directly to a memoryview slice::
The arrays are indexable and slicable from Python space just like memoryview objects, and have the same
The arrays are indexable and slicable from Python space just like memoryview objects, and have the same
attributes as memoryview objects.
attributes as memoryview objects.
CPython array module
====================
An alternative to ``cython.view.array`` is the ``array`` module in the
Python standard library. In Python 3, the ``array.array`` type supports
the buffer interface natively, so memoryviews work on top of it without
additional setup.
Starting with Cython 0.17, however, it is possible to use these arrays
as buffer providers also in Python 2. This is done through explicit
typing (e.g. a cast or assignment) as follows::
from cpython cimport array
def sum_array(array.array arr): # explicit typing required in Python 2
cdef int[:] view = arr
cdef int total
for i in range(view.shape[0]):
total += view[i]
return total
Note that the explicit typing also enables support for the old buffer
syntax for the array type. Therefore, the following also works::
from cpython cimport array
def sum_array(array.array[int] arr): # using old buffer syntax
...
Coercion to NumPy
Coercion to NumPy
=================
=================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment