<div dir="ltr"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 28, 2016 at 3:26 AM, Mirmojtaba Gharibi <span dir="ltr"><<a href="mailto:mojtaba.gharibi@gmail.com" target="_blank">mojtaba.gharibi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Jan 27, 2016 at 4:15 PM, Andrew Barnert <span dir="ltr"><<a href="mailto:abarnert@yahoo.com" target="_blank">abarnert@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><span><div>On Jan 27, 2016, at 09:55, Mirmojtaba Gharibi <<a href="mailto:mojtaba.gharibi@gmail.com" target="_blank">mojtaba.gharibi@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 27, 2016 at 2:29 AM, Andrew Barnert <span dir="ltr"><<a href="mailto:abarnert@yahoo.com" target="_blank">abarnert@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="auto"><span><div>On Jan 26, 2016, at 22:19, Mirmojtaba Gharibi <<a href="mailto:mojtaba.gharibi@gmail.com" target="_blank">mojtaba.gharibi@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div dir="ltr">Yes, I'm aware sequence unpacking.<div>There is an overlap like you mentioned, but there are things that can't be done with sequence unpacking, but can be done here.</div><div><br></div><div>For example, let's say you're given two lists that are not necessarily numbers, so you can't use numpy, but you want to apply some component-wise operator between each component. This is something you can't do with sequence unpacking or with numpy. </div></div></div></blockquote><div><br></div></span><div>Yes, you can do it with numpy.</div><div><br></div><div>Obviously you don't get the performance benefits when you aren't using "native" types (like int32) and operations that have vectorizes implementations (like adding two arrays of int32 or taking the dot product of float64 matrices), but you do still get the same elementwise operators, and even a way to apply arbitrary callables over arrays, or even other collections:</div><div><br></div><div>    >>> firsts = ['John', 'Jane']</div><div>    >>> lasts = ['Smith', 'Doe']</div><div>    >>> np.vectorize('{1}, {0}'.format)(firsts, lasts)</div><div>    array(['Smith, John', 'Doe, Jane'], dtype='<U11)</div><div><br></div></div></blockquote><div>I think the form I am suggesting is simpler and more readable. </div></div></div></div></div></blockquote><div><br></div></span><div>But the form you're suggesting doesn't work for vectorizing arbitrary functions, only for operator expressions (including simple function calls, but that doesn't help for more general function calls). The fact that numpy is a little harder to read for cases that your syntax can't handle at all is hardly a strike against numpy.</div></div></blockquote><div><br></div></span><div>I don't need to vectorize the functions. It's already being done.</div><div>Consider the ; example below:</div><div>a;b = f(x;y)</div><div>it is equivalent to</div><div>a=f(x)</div><div>b=f(y)</div><div>So in effect, in your terminology, it is already vectorized.</div><div>Similar example only with $:</div><div>a=[0,0,0,0]</div><div>x=[1,2,3,4]</div><div>$a=f($x)</div><div>is equivalent to</div><div>a=[0,0,0,0]</div><div>x=[1,2,3,4]</div><div>for i in range(len(a)):</div><div>...a[i]=f(x[i])</div><span class=""><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><br></div><div>And, as I already explained, for the cases where your form _does_ work, numpy already does it, without all the sigils:</div><div><br></div><div>    c = a + b</div><div><br></div><div>    c = a*a + 2*a*b + b*b</div><div><br></div><div>    c = (a * b).sum()</div><div><br></div><div>It also works nicely over multiple dimensions. For example, if a and b are both arrays of N 3-vectors instead of just being 3-vectors, you can still elementwise-add them just with +; you can sum all of the results with sum(axis=1); etc. How would you write any of those things with your $-syntax?</div><span><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I'm happy you brought vectorize to my attention though. I think as soon you make the statement just a bit complex, it would become really complicated with vectorize. </div></div></div></div></div></blockquote><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>For example lets say you have </div><div>x=[1,2,3,4,5,...]</div><div>y=['A','BB','CCC',...]</div><div>p=[2,3,4,6,6,...]</div><div>r=[]*n</div><div><br></div><div>$r = str(len($y*$p)+$x)</div></div></div></div></div></blockquote><div><br></div></span>As a side note, []*n is always just []. Maybe you meant [None for _ in range(n)] or [None]*n? Also, where does n come from? It doesn't seem to have anything to do with the lengths of x, y, and p. So, what happens if it's shorter than them? Or longer? With numpy, of course, that isn't a problem--there's no magic being attempted on the = operator (which is good, because = isn't an operator in Python, and I'm not sure how you'd even properly define your design, much less implement it); the operators just create arrays of the right length.<br><div><br></div></div></blockquote></span><div>n I just meant symbolically to be len(x). So please replace n with len(x). I didn't mean to confuse you. sorry.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><span class=""><div></div>Anyway, that's still mostly just operators. You _could_ wrap up an operator expression in a function to vectorize, but you almost never want to. Just use the operators directly on the arrays. <div><br></div><div>So, let's try a case that has even some minimal amount of logic, where translating to operators would be clumsy at best:<div><div><br></div><div>    @np.vectorize</div><div>    def sillyslice(y, x, p):</div><div>        if x < p: return y[x:p]</div><div>        return y[p:x]</div><div><br></div><div>    r = sillyslice(y, x, p)</div><div><div><br></div><div>Being a separate function provides all the usual benefits: sillyslice is reusable, debuggable, unit-testable, usable as a first-class object, etc. But forget that; how would you do this at all with your $-syntax?</div><br></div></div></div><div>Since you didn't answer any of my other questions, I'll snip them and repost shorter versions:</div><div><br></div></span><div>* what's wrong with using numpy? Nothing. What's wrong even with for loop or assembly for that matter? I didn't argue that it's not possible to achieve these things with assembly. </div><div>* what's wrong with APL or J or MATLAB? Not sure how relevant it is to our core of conversation. Skipping this.</div><div>* what's wrong with making the operators elementwise instead of wrapping the objects in some magic thing? The fact that whenever you </div><div>* what is the type of that magic thing anyway? It has no type. I refer you to my very first email. In that email I exactly explained what it means. It's at best a psuedo macro or something like that. It exactly is equivalent when you write</div></div></blockquote><div>a;b=f(x;y)</div><div>to</div><div>a=f(x)</div><div>b=f(y)</div><div><br></div><div>In other words, if I could interpret my code before python interpreter interpret it, I would convert the first to the latter. </div></div><br></div></div>
</blockquote></div><br></div>