[Numpy-discussion] floats for indexing, reshape - too strict ?

Chris Barker chris.barker at noaa.gov
Sat Jul 4 01:07:36 EDT 2015


On Thu, Jul 2, 2015 at 6:18 PM, <josef.pktd at gmail.com> wrote:

> round, floor, ceil don't produce integers.
>

True -- in a dynamic language, they probably should, but that's legacy that
won't change.

It's annoying, but you do need to do:

int(round(want_it_to_be_an_index))

but as they say, explicite is better than implicit.


> I'm writing library code, and I don't have control over what everyone does.
>

I'm confused -- what is the problem here -- if your library code required
an integer for an index, then that's what your users need to pass in -- how
they get that integer is under their control -- why would you want it
otherwise?

Or your code does the round|ceil|floor and int conversion -- but hen you
know what you're doing.

round, floor, ceil, and // might hide bugs or user mistakes, if we are
> supposed to get something that is "like an int" but it's. 42.6 instead.
>

then it will raise an exception -- what's the problem?

but what should 42.000000000001 do? IT seems to me, there is no choice but
an exception -- or you are really going to hide bugs.

-Chris




-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150703/4b7eed9b/attachment.html>


More information about the NumPy-Discussion mailing list