Discussion: new operators for numerical computation

Huaiyu Zhu hzhu at localhost.localdomain
Thu Jul 20 19:58:05 EDT 2000


On 20 Jul 2000 22:29:10 GMT, Ben Caradoc-Davies <bmcd at es.co.nz> wrote:

>
>I agree. Using Python's object capabilities is better than messing with the
>grammar. Although I must say the (*) forms are by far the least bad. As far as
>I'm concerned, Matlab is a poor example to follow. I've seen a number of people
>burnt by the differences between A' (adjoint) and A.' (transpose), for example. 
>

We are not going to follow everything in matlab, but it does provide a good
example for doing a lot of things. For the operations mentioned so far, the
current MatPy interface is (with minor changes that I haven't got time to
check in)

matrix      element 
 a+b         a.+b
 a-b         a.-b
 a*b         a.*b
 a/b         a./b
 sol(a,b)    none
 a**b        a.**b

 sinm(a)     sin(a)
 cosm(a)     cos(a)
 expm(a)     exp(a)
 sqrtm(a)    sqrt(a)
 ....        ...

 a.I   inverse
 a.T   transpose
 a.H   hermitian transpose
 a.C   conjugate
 
 kron(a,b)   kronicker product
 cross(a,b)  cross product (only for 3-vector)
 lie(a,b)    lie product
 ....

This is largely consistent with matlab, where I see the largest userbase
lies.  I think with the addition of just a few dozen more functions similar
to the above it already provides the majority of functionality of octave,
which perhaps have as much followers as python itself.

This in no way means that NumPy users need to change a single line of code.
In fact, because using a.__dotmul__(b) is rather tedious, I choose to cast
into NumPy arrays when there are elementwise operations in a large chunk of
code. The confusion only arrises when one needs to cast to and forth within
expressions, but it wouldn't be necessary with the new operators available.

As far as I know, many NumPy users do not feel the need for matrixwise
operators quite often and using matrixmultiply is not great pain.  When the
need is greater (eg when there are a lot of matmul in a big chunk of code)
an explicit cast into MatPy matrices may also be convenient.


Huaiyu



More information about the Python-list mailing list