[C++-sig] help with numpy
Neal Becker
ndbecker2 at gmail.com
Fri Mar 10 21:03:51 CET 2006
I'm trying to use numpy, but stuck. I think I need to register a converter,
but don't know how. Here's a test:
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/class.hpp>
#include <arrayobject.h>
namespace bp=boost::python;
static bp::object Test () {
intp dims[1];
dims[0] = 2;
return *(PyArrayObject*)PyArray_SimpleNew (1, dims, PyArray_INT);
}
BOOST_PYTHON_MODULE (test)
{
import_array();
bp::def ("Test", &Test);
}
This one doesn't even compile - can't convert
error: conversion from 'PyArrayObject' to non-scalar type
'boost::python::api::object' requested
If I try
static bp::PyArrayObject Test()...
Then at runtime I get:
TypeError: No to_python (by-value) converter found for C++ type:
PyArrayObject
I want to convice the type system that PyArrayObject is the same as;
type(numpy.zeros(2))
<type 'numpy.ndarray'>
More information about the Cplusplus-sig
mailing list