[SciPy-user] can basearray using somehow be tried already?

Perry Greenfield perry@stsci....
Fri Mar 23 14:33:56 CDT 2007


On Mar 23, 2007, at 3:08 PM, Robert Kern wrote:

> dmitrey wrote:
>
>> first of all I'm very interested in operators (matmult, dotmult  
>> etc) -
>> will they have MATLAB/Octave/omatrix/etc -like style
>> dot is present => dotwise operation
>> dot is absent => matrix operation
>> or other?
>
> No, we do not have the ability to change Python's syntax to add  
> operators. For
> the array object, operators all act element-wise. numpy also  
> provides a matrix
> object based on the array object which implements the relevant  
> operators as
> matrix operations (e.g. * is a matrix multiplication rather than  
> element-wise
> multiplication).

While strictly true, there was a cool hack a while back that had  
nearly the same effect. I forget if it was looked into and found  
wanting for this purpose. Perhaps someone remembers if there was a  
reason this couldn't be used (or wouldn't be considered symbolic  
enough). For example, one could define an effective operator |mul|"   
and use it like:

mat1 |mul| mat2

Two drawbacks were that it prevents the use of the text of the  
operator (e.g., mul in this case) for other purposes, for example for  
a variable name, and there is no way to change the precedence of the  
bracketing operator ('|' in this case). Another is that I guess you  
would have to explicitly import the operator names into your  
namespace (instead of having to refer to |numpy.mat|)

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122

Perry



More information about the SciPy-user mailing list