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

Friedrich Romstedt friedrichromstedt@gmail....
Thu Feb 11 15:03:37 CST 2010


Robert Kern:
> def numpy_ops(**ops):
>    old_ops = np.set_numeric_ops(**ops)
>    try:
>        yield
>    finally:
>        np.set_numeric_ops(**old_ops)
>
>
> with numpy_ops(multiply=...):
>    print np.array([1, 2, 3]) * np.array([1, 2, 3])

Well, at least for me in Py 2.5 this fails with:

AttributeError: 'generator' object has no attribute '__exit__'

Nevertheless it's a nice idea.  But you should definitely make
numpy_ops a proper class instance for the "with" statement, with
__enter__() and __exit__(), am I wrong?

I prefer to code my overload in such a way that it does not affect
other people's arithemetics ... But coercion is a difficult thing.

Friedrich


More information about the NumPy-Discussion mailing list