[Numpy-discussion] alternative mechanism for initializing an array

David Warde-Farley dwf@cs.toronto....
Thu Jul 16 22:22:33 CDT 2009


On 16-Jul-09, at 9:34 PM, Phillip M. Feldman wrote:

> This does the right thing sometimes, but not always.  Out[2] and  
> Out[4]
> are fine, but Out[3] is not (note the extra set of braces).  Probably
> the only right way to fix this is to modify numpy itself.


yes, to achieve out[3] you'd need myarray(1,2,3).

A .squeeze() after it would fix that, but it would also make it  
impossible to create the array [[[0]]] if you really wanted it for  
some reason.

Basically the current syntax is the only ambiguity-free way I can  
think of that makes any sense. And NumPy was designed by some very  
smart people so I doubt I'll be able to top their best idea. :P

One idea would be an object like mgrid that creates arrays via  
__getitem__ so that you could do foo[[1,2,3]] to get [[1,2,3]],  
foo[1,2,3] to get [1,2,3]... That'd get rid of a set of parens but  
it'd also be mighty confusing.

David


More information about the NumPy-Discussion mailing list