On Wed, Oct 19, 2016 at 3:55 PM, Joseph Jevnik <joe...@gmail.com> wrote:
> You could add or prototype this with quasiquotes (http://quasiquotes. > readthedocs.io/en/latest/). You just need to be able to parse the body of > your expression as a string into an array. Here is a quick example with a > parser that only accepts 2d arrays: > > ``` > # coding: quasiquotes > > import numpy as np > from quasiquotes import QuasiQuoter > > > @object.__new__ > class array(QuasiQuoter): > def quote_expr(self, expr, frame, col_offset): > return np.array([ > eval('[%s]' % d, frame.f_globals, frame.f_locals) > for d in expr.split('||') > ]) > > > def f(): > a = 1 > b = 2 > c = 3 > return [$array| a, b, c || 4, 5, 6 |] > > > if __name__ == '__main__': > print(f()) > ``` > Interesting project, thanks! If there is any actual interest in this that might be a good way to prototype it. > Personally I am not sold on replacing `[` and `]` with `|` because I like > that you can visually see where dimensions are closed. > > Yes, that issue occurred to me. But assuming a rectangular matrix, I had trouble coming up with a good example that is clearer than what you could do with this syntax. For simple arrays it isn't needed, and complicated arrays are large so picking out the "[" and "]" becomes visually harder at least for me. Do you have a specific example that you think would be clearer than what is possible with this syntax? Of course that is more of an issue with jagged arrays, but numpy doesn't support those and I am not aware of any plans to add them (dynd is another story). Also keep in mind that this would supplement the existing approach, it doesn't replace it. np.ndarray() would stay around just like list() stays around for cases where it makes sense.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/