[Numpy-discussion] Numpy helper function for __getitem__?

Phil Elson pelson.pub at gmail.com
Sat Aug 29 03:55:41 EDT 2015


Biggus also has such a function:
https://github.com/SciTools/biggus/blob/master/biggus/__init__.py#L2878
It handles newaxis outside of that function in:
https://github.com/SciTools/biggus/blob/master/biggus/__init__.py#L537.

Again, it only aims to deal with orthogonal array indexing, not numpy fancy
indexing.

I'd be surprised if Dask.array didn't have a similar function too.


HTH


On 26 August 2015 at 18:59, Stephan Hoyer <shoyer at gmail.com> wrote:

> Indeed, the helper function I wrote for xray was not designed to handle
> None/np.newaxis or non-1d Boolean indexers, because those are not valid
> indexers for xray objects. I think it could be straightforwardly extended
> to handle None simply by not counting them towards the total number of
> dimensions.
>
> On Tue, Aug 25, 2015 at 8:41 AM, Fabien <fabien.maussion at gmail.com> wrote:
>
>> I think that Stephan's function for xray is very useful. A possible
>> improvement (probably at a certain performance cost) would be to be able
>> to provide a shape instead of a number of dimensions. The output would
>> then be slices with valid start and ends.
>>
>> Current behavior:
>> In[9]: expanded_indexer(slice(None), 2)
>> Out[9]: (slice(None, None, None), slice(None, None, None))
>>
>> With shape:
>> In[9]: expanded_indexer(slice(None), (3, 4))
>> Out[9]: (slice(0, 4, 1), slice(0, 5, 1))
>>
>> But if nobody needed something like this before me, I think that I might
>> have a design problem in my code (still quite new to python).
>>
>
> Glad you found it helpful!
>
> Python's slice object has the indices method which implements this logic,
> e.g.,
>
> In [15]: s = slice(None, 10)
>
> In [16]: s.indices(100)
> Out[16]: (0, 10, 1)
>
> Cheers,
> Stephan
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150829/2403b324/attachment.html>


More information about the NumPy-Discussion mailing list