exposing C array to python namespace: NumPy and array module.

Scott David Daniels Scott.Daniels at Acm.Org
Sat Jan 1 16:20:16 EST 2005


Bo Peng wrote:
> Dear list,
> I am writing a Python extension module that needs a way to expose pieces 
> of a big C array to python. Currently, I [use] NumPy.... Users ... actually
 > change the underlying C array.
> 
> Python's array module is built-in, easy to use, but *without* a 
> FromLenAndData function! 
Python's array module is not built to do this well.  It can re-size the
array, delete elements inside the array, and other things that don't
work very well with C-managed data.  I wrote "blocks and views" to
overcome this problem.  A "View" of data can be pointed at data, and
the "view" behaves much like a Python array (except that you cannot
affect the array's size).  You can even take "slices" of the view,
which will produce a new view referring to the same base memory.  There
are two kinds of views available, read-only views and writable views.

Have a look at:
	http://members.dsl-only.net/~daniels/Block.html

to see if it addresses your problem.  It is MIT-licensed (give credit,
but feel free to use).  Let me know if it works OK, could use a tweak,
or is completely useless.  I'll be more than happy to respond to
questions.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list