Passing back an array from an extension module?

Chad Everett chat at linuxsupreme.homeip.net
Fri Jun 8 14:05:55 EDT 2001


On Fri, 8 Jun 2001 09:28:33 -0600, Bob Greschke <bob at passcal.nmt.edu> wrote:
>Is this a job for NumPy?
>
>I have a C extension function that malloc()s an array of int32s, calls
>another C function which reads/decodes a file of data and fills in the
>array.  Then I need to pass that back to the Python side for graphing
>the values.  I initially thought I could just create a tuple and pass
>that back, since nothing is going to be done with the values except to
>draw a graph, but there is the possibility of there being 16,000,000
>data points...that makes for a slightly large statement, doesn't it?
>It doesn't look like I can do this with arrays in stock Python, but it
>does look like I can do it with the NumPy arrays.  Is that correct?
>
>Now what about Py_DECREF, INCREF and all of that stuff in these
>situations?  I read through a number of posts on dejagoogle that were
>talking about this, but they only confused me more. :-)
>

Page 107 of "Python Essential Reference" re: the array modules 
states: "....The resulting arrays are not suitable for numeric
work....To create storage- and calculation-efficient arrays, use
the Numeric extension"  In other works, use NumPy.

If I am interpreting your question correctly, I think the answer
is 'yes' it's a job for NumPy.

Chapter 12 of the Numerical Python documentation is:

	12. Writing a C extension to NumPy

NumPy provides two functions for creating NumPy arrays in C:

	PyObject * PyArray_FromDims()
	PyObject * PyArray_FromDimsAndData()

The second function lets you create a NumPy array object that uses
a given memory block for its data space.





-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list