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

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

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!