Stan Schymanski wrote:
> Thanks a lot for all your help! The [f(a=i,x=j,b=k) for i,j,k in zip
> (v,w,z)] way looks useful, as I can easily see what is inserted for
> what. Looking at the other examples, I realised that most of my time
> series are likely to be imported as numpy arrays, so I will have to
> look in more detail at the numpy way. Is there an easy way of
> converting a function f into a numpy function?
> 
> Here is what I tried:
> 
> sage: import numpy
> sage: var('a b')
> sage: f = a*x^2 + b
> sage: v = numpy.array([1,2,3])
> sage: w = numpy.array([4,5,6])
> sage: z = numpy.array([7,8,9])
> sage: f(a=v,x=w,b=z)
> Traceback (click to the left for traceback)
> ...
> TypeError: 'numpy.ndarray' object is not callable
> sage: a = v
> sage: b = w
> sage: x = z
> sage: f
> array([
>                                    b + 49 a,
> 
>                                    b + 64 a,
> 
>                                    b + 81 a], dtype=object)
> sage: a*x^2 + b
> array([53, 133, 249], dtype=object)
> 
> The last output is what I want, but I don't want to type the whole
> equation in again. I am collecting all the methods and ideas that help
> me and I hope that I will be able to put it all into a tutorial one
> day.
> 


You could use a pure python function, then.  The code below does nothing 
with Sage; it would run with just python (and numpy).


sage: import numpy
sage: v = numpy.array([1,2,3])
sage: w = numpy.array([4,5,6])
sage: z = numpy.array([7,8,9])
sage: def f(a,x,b):
....:     return a*x**2+b
....:
sage: f(a=v,x=w,b=z)
array([23, 58, 117], dtype=object)


Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to