[C++-sig] How to call reshape((M,N),order='F') ?

Michele De Stefano micdestefano at gmail.com
Mon Oct 26 17:28:57 CET 2009

Hello to everyone.

I have this problem.

Assume I'm building a to-Python converter for a 3x2 matrix type,
FORTRAN storage (these are not the real dimensions of my problem, but
I give these numbers only to simplify the discussion).

Into the "convert" C++ method, first, I build a list with all the
matrix elements (lout);
then, I instantiate a boost::python::numeric::array in this way (note:
I had previously used
set_module_and_type("numpy","ndarray"), for using the NumPy's array):

boost::python::numeric::array   v(lout)

Finally, I'd like to call "reshape" on this array, in this way


But it does not work. It builds, but, on runtime, I obtain the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: an integer is required

I tried to build and re-shape a matrix entirely from Python and I
discovered that, when using reshape,
you are forced to give the second parameter as

order = 'C' or 'F'

Now the question is: is it possible to specify a named parameter from
the C++ code ?
If the answer is "yes", how ?

Thank you in advance,

Michele De Stefano

More information about the Cplusplus-sig mailing list