<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 19, 2016 at 5:32 PM, Todd <span dir="ltr"><<a href="mailto:toddrjen@gmail.com" target="_blank">toddrjen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>If there is a problem with the current options (and I'm not convinced there is) it's that it in'st a literal for multidimensional array, but rather a literal for a bunch of nested lists -- the list themselves are created, and so are all the "boxed" values in the array -- only to be pulled out and unboxed to be put in the array.</div><div><br></div></div></div></div></blockquote><div><br></div></span><div>But as you said, that is not a multidimensional array. We aren't comparing "a = [| 0, 1, 2 || 3, 4, 5 |]" and "a = [[0, 1, 2],[3, 4, 5]]", we are comparing "a = [| 0, 1, 2 || 3, 4, 5 |]" and "a = np.array([[0, 1, 2],[3, 4, 5]])". That is a bigger difference.</div></div></div></div></blockquote><div><br></div><div>Well then, you have mixed two proposals here:</div><div><br></div><div>1) a literal syntax for nd arrays -- that is not going to fly if there is NO ndarray object builtin to python. I kinda think there should be, though even then there need not be a literal for it (see Decimal). So I'd say -- get an nd array object into the standard library first, then we can talk about the literal</div><div><br></div><div>2) what the syntax should be for such a literal. OK, in this case, suggested that the way to hash that out is to start out with passing a string to a function that constructs the array -- then you could try things out without any additions to the language or the libraries -- it could be a stand-alone module that extends numpy:</div><div><br></div><div>from ndarray_literal import nda</div><div><br></div><div>my array = nda('||| 3, 4, 5 || 6, 7, 8 |||')</div><div><br></div><div>(is that legal in your notation -- I honestly am not sure)</div><div><br></div><div>and yes, that still requires typing "nda('", which you are trying to avoid. But honestly, I really have written a lot of numpy code, and writing:</div><div><br></div><div>np.array( ..... )</div><div><br></div><div>does not bother me at all. IF I did support a literal, it would be so that the object could be constructed immediately rather than by creating other python objects first (liss, usually), and then making an array from that.</div><div><br></div><div><br></div><div>If you do want to push the syntax idea further, I'd suggest going to the numpy list and seeing what folks there think.</div><div><br></div><div>But as I can't help myself. It's clear from the other posts on the list here that others find your proposed syntax as confusing as I do. but maybe it could be made more clear. Taking a page from MATLAB:</div><div><br></div><font face="monospace, monospace">1 2 3; 4 5 6</font><div><br></div><div>is a 2x3 2-d array. no in MATLAB, there only used to be matrixes, so this was pretty nice, but a bit hard to extend to multiple dimensions. But the principle is handy: one delimter for the first dimension,l a nother one for the second, etc..</div><div><br></div><div>we probably dont want to go with trying colons, and ! and who knows what else, so I liek your idea. </div><div><br></div><div>a 2-d array:</div><div><br></div><div><font face="monospace, monospace">1 | 2 | 3 || 4 | 5 | 6</font></div><div><br></div><div>(Or better)</div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">1 | 2 | 3 ||</span></div><div><span style="font-family:monospace,monospace">4 | 5 | 6</span><br></div><div><br></div><div>a 3d array:</div><div><br></div><div>
<p class="gmail-p1"><font face="monospace, monospace">0 | 1 | 2 | 3 ||</font></p><p class="gmail-p1"><font face="monospace, monospace">4 | 5 | 6 | 7 ||</font></p><p class="gmail-p1"><font face="monospace, monospace">8 | 9 | 10 | 11 |||</font></p><p class="gmail-p1"><span style="font-family:monospace,monospace"><br></span></p><p class="gmail-p1"><span style="font-family:monospace,monospace">12 | 13 | 14 | 15||</span><br></p><p class="gmail-p1"><font face="monospace, monospace">16 | 17 | 18 | 19||</font></p><p class="gmail-p1"><font face="monospace, monospace">20 | 21 | 22 | 23||</font></p></div><div><br></div><div>Notes:</div><div><br></div><div>1) guess how I wrote that? I did: <span class="gmail-s1">np.arange(</span><span class="gmail-s2">24</span><span class="gmail-s1">).reshape((</span><span class="gmail-s2">2</span><span class="gmail-s1">,</span><span class="gmail-s2">3</span><span class="gmail-s1">,</span><span class="gmail-s2">4</span><span class="gmail-s1">)) and edited the results -- making the point that maybe the current state of affairs is not so bad...</span></div>
<div><br></div><div>2) These are delimiters, rather than brackets -- so don't go at the beginning and optional at the end (like commas in python) </div><div><br></div><div>3) It doesn't use commas as all, as having a consistent system is clearer</div><div><br></div><div>4) Whitespace is insignificant as with the rest of Python -- though you want to be able to use a line ending as insignificant whitespace, so this may have to wrapped in a parentheses, or something to actually use it -- though a non-issue if it's a string</div><div><br></div><div>Hmm -- about point (3), maybe use only commas:</div><font face="monospace, monospace"><br>0, 1, 2, 3,,<br>4, 5, 6, 7,,<br>8, 9, 10, 11,,,<br><br></font></div><div class="gmail_quote"><font face="monospace, monospace">12, 13, 14, 15,,<br>16, 17, 18, 19,,<br>20, 21, 22, 23<br><br>That would be more consistent with the rest of python, and multiple commas in a row are currently a syntax error.</font></div><div class="gmail_quote"><font face="monospace, monospace"><br></font></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Even if your original data is large, I often need smaller areas when processing, for example for broadcasting or as arguments to processing functions.</div></div></div></div></blockquote><div><br></div><div>sure I do hard-coded arrays all teh time -- but not big ones, and I don't think I've ever needed more than 2D and certainly not more than 3D. and not large enough that performance matters.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>It is:<br></div></div></div></div></blockquote></span><div><span style="font-family:monospace,monospace"><br>r_[[0, 1, 2], [3, 4, 5]</span></div></div></div></div></blockquote><div><br></div><div>no, that's a shorthand for "row stack" -- and really not much better than the array() call, except a few less characters</div><div><br></div><div>I meant the np.matrix() function that Alexander pointed out -- which is only really there to make folks coming from MATLAB happier...(and it makes a Matrix object, which you likely don't want). The point was that it's easy to make such a beast for your new syntax to try it out</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">b = np.array([[ 0, 1, 2 ],<br></span><div><span style="font-family:monospace,monospace"> [ 3, 4, 5 ]])<br></span> <br></div><div>The whole point of this is to avoid the "np.array" call.<br></div></div><span class="gmail-"><div></div></span></div></div></div></blockquote><div><br></div><div>again, trying to separate out the idea of a literal, from the syntax of the literal.</div><div><br></div><div>but thinking now, Python already uses (), [], {}, and < and > -- so I don't think there are any more brackets. but why not just use commas with square brackets:</div><div><br></div><div><font face="monospace, monospace">2Darr = [1, 2, 3,,</font></div><div><font face="monospace, monospace"> 4, 5, 6] </font></div><div><br></div><div>maybe too subtle?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Yes, I understand that. But some projects are already doing that on their own. I think having a way for them to do it without losing the list constructor (which is the approach currently being taken) would be a benefit.</div></div></div></div></blockquote><div><br></div><div>huh? is anyone actually overriding the list constructor??</div><div><br></div><div>multiple dims apart (my [ and ,, example shows that you can do that with the current syntax) this is kind of like adding Decimal -- there is another type, but does it need a literal? I have maybe 90% of the code I write with an:</div><div><br></div><div>import numpy as np</div><div><br></div><div>at the top -- so yes, I kind a would like a literal, but it's really a pretty small deal -- at least once I got used to it after using MATLAB for years.</div><div><br></div><div>I'd ask folks that have been using numpy for along time -- would this really help?</div><div><br></div><div>One more problem -- with the addition of the @ operator, there have not been any use cases in the stdlib, but it is an operator, and Python already has a mechanism for operator overloading.</div><div><br></div><div>As far as I know, every python literal maps to a SINGLE type -- so creating a literal for a non existent type makes no sense at all.</div><div><br></div><div>-CHB</div></div><div><br></div>-- <br><div class="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>