[Numpy-discussion] access ndarray in C++
Wed Apr 23 13:03:15 CDT 2008
first of all, thank you for the rich spectrum of answers, especially to Joris' sample code.
What I still do not understand is the following:
One can find multiple approaches to arrays, the old numeric array and the new ndarray.
The new stuff seems to be backward compatible. However, where is a free documentation of the ndarray?
Which headers do I have to use in order to access the ndarray object that, in my eyes, should be compatible wit PyObject in some way?
I find definitions of the old array types, but none for the ndarray.
I tend to give Joris code a try; but, however, the whole situation confueses me.
Joris code (the ndarray.h) does not include any numpy object definition for instance.
All I want to do is the following:
>a = numpy.array([1,1,1])
run in C should look like this:
PyArg_ParseTuple( argv, ???? ,ndArray);
do something with ndArray.data[x][y];
Is it possible to access the ndarray object like this? I do not want to create new array objects right now, later maybe.
There must be a predefined way to access the data in C without using a custom hack.
Finally, my primary aim is to access 3dimensional arrays of floats in C.
From: firstname.lastname@example.org on behalf of Thomas Hrabe
Sent: Tue 4/22/2008 2:38 PM
Subject: [Numpy-discussion] access ndarray in C++
I am currently developing a python module in C/C++ which is supposed to access nd arrays as defined by the following command in python
a = numpy.array([1,1,1])
I want to access the array the following way and use the nd array data for further processing in C.
The example code on
(!PyArg_ParseTuple(args, "O!",&PyArray_Type, &array))
does not work for nd arrays. I always get
TypeError: argument 1 must be array, not numpy.ndarray
I assume the error is the constant provided as the third parameter, saying that the imput is of PyArray_Type and no nd array.
So here are my questions:
1. is there any good tutorial / example code for acessing nd arrays in C?
2. what is the difference between both (arrays and nd arrays? - I am new to python and heard there were different approaches to arrays and that nd arrays work better for multi dimensional applications. Is this right?)
3. which one of both will be used in the future?
Thank you in advance for your help,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion