[Numpy-discussion] vectorized function inside a class

mark markbak@gmail....
Wed Aug 8 10:37:09 CDT 2007


I am trying to figure out a way to define a vectorized function inside
a class.
This is what I tried:

class test:
	def __init__(self):
		self.x = 3.0
	def func(self,y):
		rv = self.x
		if y > self.x: rv = y
		return rv
	f = vectorize(func)


>>> m = test()
>>> m.f( m, [-20,4,6] )
array([ 3.,  4.,  6.])

But as you can see, I can only call the m.f function when I also pass
it the instance m again.
I really want to call it as
m.f( [-20,4,6] )
But then I get an error
ValueError: mismatch between python function inputs and received
arguments

Any ideas how to do this better?

Mark



More information about the Numpy-discussion mailing list