get the shape of a numpy ndarray in C++ code [boost.python]
Marc Oldenhof
foul_ole_ron1 at yahoo.com
Fri Nov 9 09:00:16 EST 2007
[sorry is half a post appeared earlier. Bloody Google groups...]
Hello,
I'm trying to use a numpy array in C++ (win2000) using boost.python.
Test code:
void test( numeric::array& nsP)
{
object shape = nsP.getshape();
int rows = extract<int>(shape[0]);
int cols = extract<int>(shape[1]);
}
At first, running it in Python got me this message:
ArgumentError: Python argument types in
d3d.wr_conn(numpy.ndarray)
did not match C++ signature:
wr_conn(class boost::python::numeric::array {lvalue})
I fixed this using this line:
numeric::array::set_module_and_type( "numpy", "ndarray");
[was that right?]
At least it got me one step further; the array is accepted. Now the
message is this:
AttributeError: 'numpy.ndarray' object has no attribute 'getshape'
Now I'm stumped. The only thing I can find is
http://www.thescripts.com/forum/showthread.php?t=644270
which regrettably ends with the same question. What's wrong here?
greets,
Marc
More information about the Python-list
mailing list