[Numpy-discussion] Scalar-ndarray arguments passed to not_equal

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Thu Feb 11 17:03:08 EST 2010


Friedrich Romstedt wrote:
> 2010/2/11 Keith Goodman <kwgoodman at gmail.com>:
>> The problem I have now is that I don't know where to place the line of
>> code that changes the meaning of numpy's equal. I don't know when
>> someone will do
> 
> Well, I think a solution is as written before to put a test whether
> the other operand is in fact a myclass instance.  If not, proceed with
> numpy's original ops.  Then it should be safe to place the overload in
> the module's code directly, altough it makes numpy a bit slower at
> all.
> 
> Or you offer Robert's solution for the with statement, but I think if
> someone imports your module he should accept that numpy's ops get
> overloaded permanently.

One danger I think wasn't mentioned with the with statement (?) is:

with changed_behaviour:
     ...
     f(arr1, arr2)
     ...

Now, f is quite likely to not know about the changed behaviour. So the 
with statement is only useful in a few restricted situations -- the kind 
of situations where a special function or method for the purpose might 
be just as easy to type.

-- 
Dag Sverre



More information about the NumPy-Discussion mailing list