<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 1, 2015 at 2:17 AM, R Hattersley <span dir="ltr"><<a href="mailto:rhattersley@gmail.com" target="_blank">rhattersley@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>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.<br><br></div>For example:<br><pre style="margin-left:40px"><span>>>></span> <span>type</span>(v)
<span><</span><span>type</span> <span><span>'</span>netCDF4.Variable<span>'</span></span><span>></span>
<span>>>></span> v.shape
(<span>240</span>, <span>37</span>, <span>49</span>)
<span>>>></span> v[(<span>0</span>, <span>1</span>), (<span>0</span>, <span>2</span>, <span>3</span>)].shape
(<span>2</span>, <span>3</span>, <span>49</span>)
<span>>>></span> np.array(v)[(<span>0</span>, <span>1</span>), (<span>0</span>, <span>2</span>, <span>3</span>)].shape
Traceback (most recent call last):
File <span><span>"</span><stdin><span>"</span></span>, line <span>1</span>, <span>in</span> <span><</span>module<span>></span>
<span>IndexError</span>: shape mismatch: indexing arrays could <span>not</span> be broadcast together <span>with</span> shapes (<span>2</span>,) (<span>3</span>,) </pre><br></div>In a <a href="https://github.com/Unidata/netcdf4-python/issues/385" target="_blank">netcdf4-python GitHub issue</a> 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.<br><br></div>1. Is there any appetite for adding that attribute (with the value `False`) to ndarray?<br><br></div>2. As <a href="https://github.com/Unidata/netcdf4-python/issues/385#issuecomment-87775034" target="_blank">suggested by shoyer</a>, is there any appetite for adding an alternative indexer to ndarray where __orthogonal_indexing__ = True? For example: myarray.ix_[(0,1), (0, 2, 3)]<br></div></div></blockquote><div><br></div><div>Is there any other package implementing non-orthogonal indexing aside from numpy? I understand that it would be nice to do:</div><div><br></div><div>if x.__orthogonal_indexing__:</div><div> return x[idx]</div><div>else:</div><div> return x.ix_[idx]</div><div><br></div><div>But I think you would get the exact same result doing:</div><div><br></div><div>if isinstance(x, np.ndarray):</div><div> return x[np.ix_(*idx)]</div><div>else:</div><div> return x[idx]</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Jaime</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div>Richard<br></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">(\__/)<br>( O.o)<br>( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.</div>
</div></div>