# [Numpy-discussion] Python scalar float indices into array work - but not for array indices - why ?

Sebastian Haase seb.haase@gmail....
Wed Nov 17 13:11:11 CST 2010

```On Wed, Nov 17, 2010 at 7:48 PM, Nathaniel Smith <njs@pobox.com> wrote:
> On Wed, Nov 17, 2010 at 10:32 AM, Sebastian Haase <seb.haase@gmail.com> wrote:
>> On Wed, Nov 17, 2010 at 7:26 PM, Robert Kern <robert.kern@gmail.com> wrote:
>>> On Wed, Nov 17, 2010 at 12:20, Sebastian Haase <seb.haase@gmail.com> wrote:
>>>> Why does numpy not accept float arrays as indices ?
>>>> I was very happy and quite surprised once I found out that it worked
>>>> at all for Python float scalars,
>>>> but would it not just be consequent to also allow float ndarrays then ?
>>>
>>> It only works for float scalars by accident. Do not rely on it.
>>
>> Could you be more specific ?  As a feature, it for sure can be useful.
>
> I think Robert Kern has the same intuition as me: that supporting
> float indices is pointless. So, can you give any *specific examples*
> of things you can do with float indices that would be difficult or
> more expensive using integer indices? That's probably the best way to
> convince people.
>
> -- Nathaniel
Well,
suppose you have 2 vectors of floating point coordinates `x` and `y`
and you want to do operations utilizing fancy indexing like
image[ [x,y] ] +=  1

As I just realized, this specific case seems to be addressed by histogram2d,
however, if float indices would work this would of course be much more
general: higher dimensionality and not just '+=' operations.

Finally, I just started wondering if numexpr could help here: then one
could, for example, even do proper rounding (like: image[ [x+.5,y+5] ]
+=  1) without creating a temporary array.

Regards,
Sebastian
```