[Numpy-discussion] Expanding an array by assignment
Fernando.Perez at colorado.edu
Thu Feb 17 12:01:15 CST 2005
Travis Oliphant wrote:
> I'm not sure what you meant by this. Did you mean being able to expand
> an array only by assignment?
> a = zeros(2) a (2,1) array
> a[1,0] = 1 (resizes a behind the scenes to a 2x2 array and then sets
> the 1,0 element)?
Mmmh. I'm not sure I like the idea of an assignment triggering a silent
resize/reshape event. Explicit is better than implicit and all that...
I could see this kind of magical behavior easily causing silent, extremely
hard to find bugs in a big program.
I may be missing something, but I'd be -1 on this.
The 'invalid indices in slices' is basically just sytnactic sugar for a
try/except block, and it's well-documented behavior in the base language,
across all its sequence types:
In : ll=
In : tt=()
In : ss=''
In : ll[0:1]
In : tt[0:1]
In : ss[0:1]
So in my view at least, this behavior of python isn't a good justification for
a silent resize/reshape (which could, I'm sure, be also potentially explosive
memory-wise) in numerix arrays.
More information about the Numpy-discussion