[Numpy-discussion] Adding a flag to allow integer array access and masking

Travis Oliphant oliphant at ee.byu.edu
Wed Mar 6 10:50:08 CST 2002

> Please, no.   There are many short names that you could use that would
> avoid overloading the [] operator.   Especially in Python, where
> one cannot trivially decide the type of a variable,
> the behavior should change as little as possible as the type
> of each variable changes.

Right now, what I'm suggesting fails with an error.  Everyone talks about
things not changing when types change but this is actually almost never
the case.

There is almost always a different behavior if the objects have different

Are you opposed to anything going inside the [] operator to help indicate
how the objects inside should be interpreted

> Here, the indexing operation changes completely if you change the
> last index from an int to an array.  That means you have to
> execute the code to understand it -- one can't just look and
> assume from local syntax.

No, only a very specific kind of array.  Currently, such a change gives
you an error.  And if the array was in the wrong place it would also give
you an error.

Your concerns seem motivated by not really understanding the suggested
change.  Could you provide me with other examples that show precisely what
you mean?

> Besides, you know some idiot is going to eventually write
> code that looks like this:
> def access(a, b, x):
> 	return a[b, x]  # I think that a must be a 2-D array...
> # 1000 lines later...
> access(a, _I)	# Whoops all my assumptions were wrong...

I have no idea, what your concern is here.  This would result in an error
currently and under the scheme I suggested.


More information about the Numpy-discussion mailing list