8 Mar 2004 afayolle   » (Master)

This may be old news for most people using Numeric Python on a daily basis, but I've just "discovered" that Numeric ufuncs can be applied to class instances, if they implement the right interface, which is a method with the same name as the ufunc.

One dumb example :

class ZeroAngle:
    def sin(self):
        return 0.
    def tan(self):
        return 0
    def cos(self):
        return 1

a = ZeroAngle() import Numeric as n print n.cos(za) print n.sin(za)

This of course does not work with the functions in math or cmath, which try to coerce there argument to float.

A very nice usage of this is in Konrad Hinsen's Scientific.Functions.Derivatives (part of the Scientific Python package)

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!