On Sat, Mar 2, 2013 at 2:29 AM, G B <g.c.b.at.w...@gmail.com> wrote:
> Ah thanks-- always comforting to know I'm not the first person to
> complain...  =)  And the broadcasting argument makes the current design less
> mystifying.
>
> In my case, I have a sympy equation that I lambdify to a function that I
> then want to plot.  I wind up with something like this:
> xx=linspace(...)
> f=lambdify(x,exp,"numpy")
> y=f(xx)
> plot(xx,y)
>
> That snippet of code worked fine until it ran on an expression that
> simplified to a constant.  I could solve the problem by placing special
> handling around y before plot, but that feels inelegant.
>
> I understand the broadcasting argument from a numpy centric view, but is
> that the model that lambdify should follow?  I feel as though in numpyland
> you're more likely to know the shape of your function, and thus would know
> from the outset whether y needed to be reshaped.
>
> In sympyland, the function itself is a variable, so special handling of y
> becomes necessary boilerplate.
>
> Of course, I've explicitly told lambdify to create a "numpy" function, so
> it's not unreasonable that it behave in the numpy way.  Maybe this is a
> place for a keyword argument?
>
> Maybe I'm giving too much weight to my own particular use case, but is this
> a discussion worth reopening?

Yes, if you feel that your use case gives a good argument to change
it, then definitely.  I personally don't use numpy, so I can't really
comment on it much myself.

>From what I remember, the reason that it does this is not because of a
design choice, but because of the way that zero-argument lambdas work
compared to multi-argument ones (basically, multi_argument(array)
gives an array, but zero_argument() gives a constant, because it is
never broadcast).  So without any additional modifications, this is
the behavior, but that doesn't mean that it is the right one.

Aaron Meurer

>
>
>
> On Saturday, March 2, 2013 12:21:20 AM UTC-8, Aaron Meurer wrote:
>>
>> See https://code.google.com/p/sympy/issues/detail?id=2543 for some
>> discussion on this.
>>
>> Aaron Meurer
>>
>> On Fri, Mar 1, 2013 at 8:53 PM, G B <g.c.b....@gmail.com> wrote:
>> > This is kind of a degenerate case, but personally I think it should
>> > behave
>> > differently than it does currently.
>> >
>> > f1=lambdify(x,2*x,"numpy")
>> > f2=lambdify(x,S(1),"numpy")
>> >
>> > f1(array([1,2,3])   --> [2,4,6]
>> > f2(array([1,2,3])   --> [1]
>> >
>> > I feel that f2 should return [1,1,1] in that situation.  Am I
>> > misinterpreting that?
>> >
>> > Cheers--
>> >  Greg
>> >
>> >
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "sympy" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to sympy+un...@googlegroups.com.
>> > To post to this group, send email to sy...@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/sympy?hl=en.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to