python interface to c++ class

Travis Oliphant olipt at mayo.edu
Wed Apr 14 18:01:02 EDT 1999


> for example In C++,we can enjoy following
> operations.
> (f_matrix: matrix class for float, d_matrix: for
> double)
> 
>    1. f_matrix x1,x2; float y; x2=y*x1; (operation
> between different types)

The Numeric module has these types of object defined (but extended to N-D
arrays).  Operations between different types is supported by
sophisticated broadcasting rules.

>    2. x1(1,2)=3.4; (substitution for matrix
> element)

With Numeric one can substitute for array (matrix) elements or array
slices (start, stop, step).

>    3. d_matrix z; z=x1;
>    (auto conversion from float matrix to another
> type(d_matrix))
> 

Since Python is not a staticly typed language, typing z = x1 when x1 is a
Numeric multiarray object will just bind the name z to the object x1.  If
x1 is a Float array and you want a double array, you say.

z = x1.astype('d')


It sounds like you should really check out the Numeric module and see if
it doesn't fit your needs.  It is quite a useful tool.


Best,

Travis








More information about the Python-list mailing list