[Python-Dev] Pre-PEP: Allow Empty Subscript List Without Parentheses
ncoghlan at gmail.com
Sat Jun 10 05:41:41 CEST 2006
Greg Ewing wrote:
> Tim Hochberg wrote:
>> In Numpy, a 0-D array [for example, array(5)] is almost, but not quite,
>> equivalent to scalar [for example, 5]. The difference is that the
>> former is mutable.
> Hmmm, I hadn't considered that. I suppose this is
> something that arises from NumPy's "view" semantics
> of indexing and slicing.
I think it more comes from the n-dimensional array approach - 'n=0' is then a
natural issue to consider. The Python core doesn't really get into that space,
because it only really considers 1-dimensional sequences.
>> Whether that makes x desirable I won't venture an opinion. I don't see
>> a lot of use of 0-D arrays in practice.
> Actually, I *have* just thought of a use for it:
> def outer():
> x = array(0)
> def inner():
> x = 42
> Bingo - write access to outer scopes!
> Okay, I'm +0 on this now. But for that use, we'd need
> a more convenient way of creating one than importing
> NumPy and using array().
Another 'initially -1, but +0 after reading the PEP & thread' here.
Also, with Travis's proposed dimarray type hopefully arriving in time for
Python 2.6, I'd expect for this to be as simple as doing 'from array import
dimarray' at the top of the module, and then:
x = dimarray(0)
x = 42
My personal hopes for the dimarray type are that it will have an internal data
representation that's compatible with numpy, but Python-level semantics that
are closer to those of the rest of the Python core (such as providing
copy-on-slice behaviour instead of numpy's view-on-slice).
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev