Em Ter, 2008-11-25 às 08:07 -0800, Mike Hansen escreveu: > Hi, > > On Tue, Nov 25, 2008 at 6:22 AM, Stan Schymanski <[EMAIL PROTECTED]> wrote: > > > > Hi Mike, > > > > This is pretty cool, thanks! Is there something equivalent for passing > > a function f to python or numpy? > > I'm not exactly sure what you mean by this so I'll take a guess. > Given, your f=a*x^2+b, do you want to be able to get an object that is > / acts like the Python > > def f(a,b,x): > return a*x**2 + b > > ? > > For numpy, if you had an expression like f = sin(x) + 2, you'd want > something like, > > def f(x): > return numpy.sin(x)+2 > > so that it'd work well with numpy arrays? > > If so, then none of this is currently possible :-) But, it's > primarily not possible since no one has seriously thought about doing > this before. I think it would definitely make Sage's symbolic stuff > much more useful to a wider range of people. It's also probably not > too far off with the Pynac stuff. > > I'm sending this to sage-devel to get comments / feedback from people there. > > --Mike
Hi, Actually, I have been thinking about it and discussing that in irc for some time now, since I currently do my projects using pure numpy (without sage). Also, I have been trying to do some stuff in sage in a way that I wanted exactly that to work, since (I presume) doing all the calculations of a function in sage, then simplifying, and only then applying to a big numerical array "should" be more efficient than just doing all ops directly to the array. So far, the results I have are that most ways to do that have a lot of type conversions, because applying a sage function to a each element of the array will return an array of sage objects. I'm doing sage: array(map(f, my_data)) Which will return an array of sage objects. To get it back to numpy types I use the astype() function, but I think is a terrible waste on performance and memory. OBS: this also only works for 1-D arrays, so one also has to do some reshaping magic to work on n-dimension arrays. Also, don't forget that for doing operations on arrays you sometimes have to coerce numbers to raw ones, otherwise they will pass sage types to numpy and generate arrays of sage objects. So far, I'm doing everything in pure python + numpy, for performance reasons, though it would be nice to have some sage powers in the future. Well, that's my 2 cents. Ronan Paixão --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
