wasm-demo/demo/ermis-f/python_m/cur/0980

54 lines
1.3 KiB
Plaintext

From: olipt at mayo.edu (Travis Oliphant)
Date: Wed, 14 Apr 1999 17:01:02 -0500
Subject: python interface to c++ class
In-Reply-To: <3714E388.CD434E8A@pk.highway.ne.jp>
References: <3714E388.CD434E8A@pk.highway.ne.jp>
Message-ID: <Pine.LNX.4.04.9904141653500.16523-100000@us2.mayo.edu>
X-UID: 980
> 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