Jason Grout wrote: >> 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)
I should note that the smarts in the above are in the numpy array class, which does operations element-by-element (i.e., v*w is the element-by-element multiplication of arrays v and w). Some of the other solutions, including the list comprehension solution, had the smarts residing outside of the data object. Thus, those solutions will work with plain python lists, whereas you can use the simpler method above with numpy arrays. Either way, you eventually have a loop. With numpy, though, the array can do the loops itself without you explicitly coding one. 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 -~----------~----~----~----~------~----~------~--~---