In running a program I've written, I added a summation as follows:
>>> Sum((i-i%2)/2, (i, 1, 10)).doit()
It's actually a liitle more involved than that, but either way below
is the output to that command:
---
TypeError
On Thu, Mar 4, 2010 at 8:46 AM, archeryguru2000
wrote:
> In running a program I've written, I added a summation as follows:
>
Sum((i-i%2)/2, (i, 1, 10)).doit()
>
> It's actually a liitle more involved than that, but either way below
> is the output to that command:
>
> ---
Ondrej, thanks for the reply.
What I mean is exactly that, i%2. If 'i' is even, i%2 = 0, if 'i' is
odd, i%2 = 1. How else would one write that?
I have a very large program that actually uses this 'remainder'
operator many times. However, only in the summation do I have any
problems with it
Hi,
> We tried lambdify but there a few problems. Many of the for loops we
> were using were of the form
> for i in I:
> numerically evaluate X
> Y = f(X)
> for a in A:
> EXPR.subs(a,Y)
> ...
First, a few clarifications.
1) I am not 100% with sympy internals, but AFAICS a is a sympy
On Thu, Mar 4, 2010 at 10:10 AM, Chad File wrote:
> Ondrej, thanks for the reply.
>
> What I mean is exactly that, i%2. If 'i' is even, i%2 = 0, if 'i' is odd,
> i%2 = 1. How else would one write that?
>
> I have a very large program that actually uses this 'remainder' operator
> many times. Ho
On Thu, Mar 4, 2010 at 10:21 AM, Ondrej Certik wrote:
> On Thu, Mar 4, 2010 at 10:10 AM, Chad File wrote:
>> Ondrej, thanks for the reply.
>>
>> What I mean is exactly that, i%2. If 'i' is even, i%2 = 0, if 'i' is odd,
>> i%2 = 1. How else would one write that?
>>
>> I have a very large program
On Thu, Mar 4, 2010 at 11:50 PM, Rohit Garg wrote:
> First, a few clarifications.
>
> 1) I am not 100% with sympy internals, but AFAICS a is a sympy
> expression. And sympy only allows single line expressions. By that I
> mean, expressions involving only the 4 arithmetic operators,
> mathematical
On Thu, Mar 4, 2010 at 10:20 AM, Rohit Garg wrote:
> Hi,
>
>> We tried lambdify but there a few problems. Many of the for loops we
>> were using were of the form
>> for i in I:
>> numerically evaluate X
>> Y = f(X)
>> for a in A:
>> EXPR.subs(a,Y)
>> ...
>
> First, a few clarification
Ondrej,
The only opportunity with the below statement
Sum(f(i), (i, 1, 2*n)) = Sum(f(2*k)+f(2*k-1), (k, 1, n))
is that 2*n would have to be even. And in my case it is certainly not
always true. This summation is part of a function that is called many
hundreds of times. And each time it is
On Thu, Mar 4, 2010 at 11:40 AM, Chad File wrote:
> Ondrej,
> The only opportunity with the below statement
>
> Sum(f(i), (i, 1, 2*n)) = Sum(f(2*k)+f(2*k-1), (k, 1, n))
>
> is that 2*n would have to be even. And in my case it is certainly not
> always true. This summation is part of a function
You are making your life unnecessarily difficult. The standard way to
alternate between
numbers is to use (-1)**i. In this case, you could do ((-1)**(i+1) + 1)/2.
Another option
is to use sin or cos, for example, here you could use abs(sin(pi/2*i)).
With that being said, maybe we should creat
Thank Aaron,
I'm not sure why I didn't think of (-1)**i in the first place (or the
cos/sin equivalent). I have to run for now, but tomorrow morning I'll
give that a shot.
Thanks,
--
~~archery~~
Aaron S. Meurer wrote:
You are making your life unnecessarily difficult. The standard way t
Indeed, here is how to do your sum:
In [15]: Sum((i-((-1)**(i+1) + 1)/2)/2, (i, 1, 10)).doit()
Out[15]: 25
e.g. just replace i%2 by ((-1)**(i+1) + 1)/2 and things just work.
Thanks Aaron!
Ondrej
On Thu, Mar 4, 2010 at 12:30 PM, Chad File wrote:
> Thank Aaron,
> I'm not sure why I didn't think
On Mar 3, 8:24 pm, wflynny wrote:
> Hi!
>
> I have a huge sympy expression and in our current implementation, I
> numerically evaluate the expression hundreds to thousands of times
> using .subs, lambda functions, list comprehension, etc. As you can
> imagine, this is very slow.
>
> I am looking a
> Thanks Rohit for the help. I need to understand the problem better. In
> my experience, the best way is to use lambdify with numpy, then create
> a numpy array of values and pass it to it --- this then uses numpy to
> evaluate for lots of values at once and it is *very* efficient.
This is anoth
15 matches
Mail list logo