a=[ lambda t: t**n for n in range(4) ]

Michael Spencer mahs at telcopartners.com
Fri Apr 22 18:33:34 EDT 2005


mehmetmutigozel at gmail.com wrote:
> Thanx for your replies.
> 
> I'm looking for array of functions.
> Something like a=[ sin(x) , cos(x) ]
> 
> 
>>>>x=0.0
>>>>a
> 
> [0, 1]
> 
>>>>x=1.0
>>>>a
> 
> ...
> 
> of course it can be made by
> 
>>>>def cratearray(x):
> 
> ...           ~~~~
> ...           return a
> a=createarray(1.0)
> 
> but this isn't what i am asking for. something automized.
> 
Still, guessing, but perhaps this:

  >>> def make_func_map(*funcs):
  ...     def f(x):
  ...         return [func(x) for func in funcs]
  ...     return f
  ...
  >>> from math import sin, cos, pi
  >>> a = make_func_map(sin, cos)
  >>> a(0)
  [0.0, 1.0]
  >>> a(pi)
  [1.2246063538223773e-016, -1.0]
  >>>

Michael




More information about the Python-list mailing list