Hi Jason,
Thanks for that. I still have a problem, as I use sage to derive a
complicated equation first, and then I need to get that function into
python. Say this function is called f, I tried the following:
import numpy
var('a b x')
f = a*x^2 + b
v = numpy.array([1,2,3])
w = numpy.array([4,5,6
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.
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 h
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 t
On Wed, Nov 19, 2008 at 12:19 PM, Jason Grout
<[EMAIL PROTECTED]> wrote:
>
> Stan Schymanski wrote:
>> Hi Mike and Jason,
>>
>> Thanks a lot for the quick response. My problem becomes a bit more
>> obvious if I have a function of several variables. Then the map
>> function becomes somehow impracti
And a (not very robust) version which works with keyword arguments too:
def threaded(f):
from functools import wraps
def wrapper(*args, **kwds):
n = max(map(len, args) + map(len, kwds.values()) + [0])
if n == 0:
return []
new_args = zip(*args) if len(ar
Stan Schymanski wrote:
> Hi Mike and Jason,
>
> Thanks a lot for the quick response. My problem becomes a bit more
> obvious if I have a function of several variables. Then the map
> function becomes somehow impractical because I can't define which list
> is used for which variable. List comprehe
Its not completely clear to me which arguments you want substituted
for, but assuming you would like the v-values to be x, w-values for a,
and z-values for b, you could do:
sage: var('a b c')
sage: f = a*x^2+b
sage: v = [1,2,3]
sage: w = [4,5,6]
sage: z = [7,8,9]
sage: [f.subs({x:v1,a:v2,b:v3}) f
Hi Mike and Jason,
Thanks a lot for the quick response. My problem becomes a bit more
obvious if I have a function of several variables. Then the map
function becomes somehow impractical because I can't define which list
is used for which variable. List comprehensions also get a lot more
difficul
Mike Hansen wrote:
> Hi Stan,
>
> You should use Python's list comprehensions to do that:
>
> sage: f = 2*x^3+1
> sage: v = [1,2,3]
> sage: [f(x=a) for a in v]
> [3, 17, 55]
>
> or you could do
>
> sage: map(f, v)
> [3, 17, 55]
The question was: Is there an easy way of
performing operations o
Hi Stan,
You should use Python's list comprehensions to do that:
sage: f = 2*x^3+1
sage: v = [1,2,3]
sage: [f(x=a) for a in v]
[3, 17, 55]
or you could do
sage: map(f, v)
[3, 17, 55]
--Mike
--~--~-~--~~~---~--~~
To post to this group, send email to sage-suppor
11 matches
Mail list logo