On Wed, Apr 1, 2015 at 2:17 AM, R Hattersley <rhattersley@gmail.com> wrote:
There are two different interpretations in common use of how to handle multi-valued (array/sequence) indexes. The numpy style is to consider all multi-valued indices together which allows arbitrary points to be extracted. The orthogonal style (e.g. as provided by netcdf4-python) is to consider each multi-valued index independently.

For example:
>>> type(v)
<type 'netCDF4.Variable'>
>>> v.shape
(240, 37, 49)
>>> v[(0, 1), (0, 2, 3)].shape
(2, 3, 49)
>>> np.array(v)[(0, 1), (0, 2, 3)].shape
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (3,) 

In a netcdf4-python GitHub issue the authors of various orthogonal indexing packages have been discussing how to distinguish the two behaviours and have currently settled on a boolean __orthogonal_indexing__ attribute.

1. Is there any appetite for adding that attribute (with the value `False`) to ndarray?

2. As suggested by shoyer, is there any appetite for adding an alternative indexer to ndarray where __orthogonal_indexing__ = True? For example: myarray.ix_[(0,1), (0, 2, 3)]

Is there any other package implementing non-orthogonal indexing aside from numpy? I understand that it would be nice to do:

if x.__orthogonal_indexing__:
    return x[idx]
else:
    return x.ix_[idx]

But I think you would get the exact same result doing:

if isinstance(x, np.ndarray):
    return x[np.ix_(*idx)]
else:
    return x[idx]

If `not x.__orthogonal_indexing__` is going to be a proxy for `isinstance(x, ndarray)` I don't really see the point of disguising it, explicit is better than implicit and all that.

If the functionality is lacking, e,g, use of slices in `np.ix_`, I'm all for improving that to provide the full functionality of "orthogonal indexing". I just need a little more convincing that those new attributes/indexers are going to ever see any real use.

Jaime

Richard

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion




--
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.