[Numpy-discussion] non-integer index misfeature?

Ralf Gommers ralf.gommers at gmail.com
Wed Dec 12 15:20:04 EST 2012


On Tue, Dec 11, 2012 at 5:44 PM, Neal Becker <ndbecker2 at gmail.com> wrote:

> I think it's a misfeature that a floating point is silently accepted as an
> index.  I would prefer a warning for:
>
> bins = np.arange (...)
>
> for b in bins:
> ...
>   w[b] = blah
>
> when I meant:
>
> for ib,b in enumerate (bins):
>   w[ib] = blah
>

Agreed. Scipy.special functions were just changed to generate warnings on
truncation of float inputs where ints are expected (only if truncation
changes the value, so 3.0 is silent and 3.1 is not).

For numpy indexing this may not be appropriate though; checking every index
value used could slow things down and/or be quite disruptive.

Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20121212/510ebe36/attachment.html>


More information about the NumPy-Discussion mailing list