Re: Numpy ndarray to C array

2011-12-08 Thread Robert Kern
On 12/8/11 7:56 PM, Enrico wrote: I am trying to pass a multi-dimensional ndarray to C as a multi- dimensional C array for the purposes of passing it to mathematica. They already have a wrapper for a 1-D Python list. where the list is copied to "list". Shown below: I would like t

Numpy ndarray to C array

2011-12-08 Thread Enrico
I am trying to pass a multi-dimensional ndarray to C as a multi- dimensional C array for the purposes of passing it to mathematica. They already have a wrapper for a 1-D Python list. where the list is copied to "list". Shown below: static PyObject * mathlink_PutIntegerList(mathlink_

c array

2009-04-29 Thread luca72
hello i'm using ctypes i have this c function PREF0 short usb_tc08_get_single ( short handle, float * temp, short * overflow_flags, short units); where : nt main(void) { short handle = 0; /* The handle to a TC-08 returned by usb_tc08_open_unit() */ char selection =

Re: Converting a c array to python list

2007-03-04 Thread zefciu
Dennis Lee Bieber wrote: > Written properly, all it returns is the address of that array data > -- there is no massive copying of data.. I know :) That's why I want to know how to write it properly. zefciu -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a c array to python list

2007-03-03 Thread zefciu
Russell E. Owen wrote: > > It might help to have a clearer idea of why you want to do this. > I am writing a Mandelbrot fractal generator with Tkinter interface. Now the generation works like this - there is a loop in python which iterates through fractal's pixels and for each of them calls a

Re: Converting a c array to python list

2007-03-02 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, zefciu <[EMAIL PROTECTED]> wrote: > Hi! > > I want to embed a function in my python application, that creates a > two-dimensional array of integers and passes it as a list (preferably a > list of lists, but that is not necessary, as the python function knows > the

Re: Converting a c array to python list

2007-03-02 Thread zefciu
I have just read about buffer and array objects and I think one of them could be fit for my need. However there are two questions. If i make a buffer from a part of dynamically allocated memory, what would free it? Should it be allocated with malloc or some python-specific function? How on eart

Re: Converting a c array to python list

2007-03-01 Thread Scott David Daniels
other_way below: ... view = block.View(...) stride = <> one_way = [view[n: n + stride] for n in range(0, len(view), stride)] other_way = [view[n::stride] for n in range(stride)] ... One of these will give you row-major, and the other column-major access to the live data

Converting a c array to python list

2007-03-01 Thread zefciu
Hi! I want to embed a function in my python application, that creates a two-dimensional array of integers and passes it as a list (preferably a list of lists, but that is not necessary, as the python function knows the dimensions of this array). As I read the reference, I see, that I must first i

Re: void * C array to a Numpy array using Swig

2006-01-13 Thread Travis E. Oliphant
Krish wrote: > Hello People > > I hope I am On Topic. Anyways, here is my problem. Any insights would > be really appreciated. Posting to the [EMAIL PROTECTED] list would help generate more responses, I think. > > I have wrapped a C IO module using SWIG -> Python Module. Suppose the > name of

Re: void * C array to a Numpy array using Swig

2006-01-13 Thread Krish
Thanks Jon Much I will implement your method for the time being. I am sure there is some method which doesn't copy the data but uses the existing data. I mean essentially we should build a PyArrayObject with the data intact and other parameters filled. If someone sheds some light, would be awesom

Re: void * C array to a Numpy array using Swig

2006-01-12 Thread Travis E. Oliphant
Philip Austin wrote: > "Travis E. Oliphant" <[EMAIL PROTECTED]> writes: > > >>Krish wrote: > > >>Yes, you are right that you need to use typemaps. It's been awhile >>since I did this kind of thing, but here are some pointers. > > > Also, there's http://geosci.uchicago.edu/csc/numptr > This

Re: void * C array to a Numpy array using Swig

2006-01-12 Thread Philip Austin
"Travis E. Oliphant" <[EMAIL PROTECTED]> writes: > Krish wrote: > Yes, you are right that you need to use typemaps. It's been awhile > since I did this kind of thing, but here are some pointers. Also, there's http://geosci.uchicago.edu/csc/numptr -- http://mail.python.org/mailman/listinfo/p

Re: void * C array to a Numpy array using Swig

2006-01-12 Thread Jon
Krish, In case you find a good solution, I am also looking for one! For now I essentially use helper functions on the c side which wrap in SWIG to return the data as a string in python. That string can then be converted to a numpy array using the fromstring function. This is inefficient as it doe

void * C array to a Numpy array using Swig

2006-01-11 Thread Krish
Hello People I hope I am On Topic. Anyways, here is my problem. Any insights would be really appreciated. I have wrapped a C IO module using SWIG -> Python Module. Suppose the name of the module is "imageio" and the reader function from the file is image_read() which returns an object ( "filled"

Re: Converting C++ array into Python

2005-10-12 Thread Larry Bates
Yes, I'm normally calling .DLL function with a defined API and memory layout. May not be optimal, when you don't have the C code available and the data structure is part of the API it works just fine. -Larry Bates Jorgen Grahn wrote: > On Wed, 12 Oct 2005 11:13:52 -0500, Larry Bates <[EMAIL PROT

Re: Converting C++ array into Python

2005-10-12 Thread Jorgen Grahn
On Wed, 12 Oct 2005 11:13:52 -0500, Larry Bates <[EMAIL PROTECTED]> wrote: > Like others, without more information on what you have tried we are > just guessing. Many times I've used the struct.unpack() module to > unpack C "arrays" into python objects. In that case, it sounds like you make yours

Re: Converting C++ array into Python

2005-10-12 Thread Larry Bates
f you > give a clear example of what you are trying to accomplish, how, and why it > fails. > > Adriaan Renting. > > >>>>"Deshdeep, Singh (IE10)" <[EMAIL PROTECTED]> 10/04/05 7:33 am >>> > > > I am extending C++ applica

Re: Converting C++ array into Python

2005-10-12 Thread Adriaan Renting
accomplish, how, and why it fails. Adriaan Renting. >>>"Deshdeep, Singh (IE10)" <[EMAIL PROTECTED]> 10/04/05 7:33 am >>> I am extending C++ application with python. I am not able to convert a C++ array in Python. If anyone has the experience of the

Converting C++ array into Python

2005-10-03 Thread Deshdeep, Singh (IE10)
I am extending C++ application with python. I am not able to convert a C++ array in Python.   If anyone has the experience of the below :- 1)   How to handle the C++ array in the Python code and how to input that from the script ?   Awaiting for the solution   Regards DD

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

2005-01-01 Thread Scott David Daniels
Bo Peng wrote: Scott David Daniels wrote: I wrote "blocks and views" to overcome this problem. I was too impatient to wait for your reply. :-) I call 21-hour turnaround over New Year's Eve pretty good. Clearly I will never be quick enough for you ;-). Since I presented this at the Vancouver Pytho

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

2005-01-01 Thread Bo Peng
Scott David Daniels wrote: 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. As always the case, this problem have b

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

2005-01-01 Thread Scott David Daniels
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

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

2005-01-01 Thread Raymond L. Buvel
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 am using NumPy like the following: PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE, char*buf); Users will get a Numeric Array object

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

2005-01-01 Thread Craig Ringer
On Sat, 2005-01-01 at 10:27 -0600, Bo Peng wrote: > Sorry if I was not clear enough. I was talking about the differece > between python array module > (http://docs.python.org/lib/module-array.html, Modules/arraymodule.c in > the source tree) and NumPy array. They both use C-style memory block

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

2005-01-01 Thread Bo Peng
Craig Ringer wrote: On Sat, 2005-01-01 at 08:18, Bo Peng wrote: Python's array module is built-in, easy to use, but *without* a FromLenAndData function! Even the buffer interface provides only 'get buffer' but no 'set buffer' functions. Could anyone tell me how I can create an array object from

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

2005-01-01 Thread Craig Ringer
create an array object from existing data? Python has no array objects in the core language, only lists. The distinction is important when discussing numarray etc, because Python lists and NumPy etc arrays are very different. While you can build a Python list from a subsection of your C array, c

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

2004-12-31 Thread Bo Peng
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 am using NumPy like the following: PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE, char*buf); Users will get a Numeric Array object and can change