[Numpy-discussion] numpy.floor() is supposed to return an int, but returns a float

Tim Hochberg tim.hochberg at cox.net
Sun Apr 9 15:30:02 CDT 2006


Webb Sprague wrote:

>Could someone explain this behavior:
>
>In [13]: type(N.floor(1))
>Out[13]: <type 'float64scalar'>
>
>In [14]: N.floor?
>Type:           ufunc
>String Form:    <ufunc 'floor'>
>Namespace:      Interactive
>Docstring:
>    y = floor(x) elementwise largest integer <= x
>
>I wouldn't complain, except the only time I use floor() is to make
>indices (dividing ages by age widths, for example).
>  
>
Well, floor returns an integer, but not an int -- it's an integral 
floating point value. What you want is:

 numpy.floor(1).astype(int)
   
(If you're only using scalars, you might also consider int(floor(x)) 
instead.

Regards,

-tim



>Thanks!
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by xPML, a groundbreaking scripting language
>that extends applications into web and mobile media. Attend the live webcast
>and join the prime developer group breaking into this new coding territory!
>http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
>_______________________________________________
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
>
>  
>






More information about the Numpy-discussion mailing list