[Numpy-discussion] floor with dtype

Renato Fabbri renato.fabbri at gmail.com
Wed Sep 27 04:36:45 EDT 2017


>>> myarray.astype(n.int)
returns the same values as
>>> n.floor(myarray).astype(n.int)
for positive values??

And the same as
>>> n.trunc(myarray)
for any value?



On Mon, Sep 25, 2017 at 5:36 PM, Mark Bakker <markbak at gmail.com> wrote:

> > On 2017-09-25 10:59, Renato Fabbri wrote:
>
>> > > """
>> > > In [3]: n.floor(n.linspace(0,5,7), dtype=n.int <http://n.int>)
>> > > ------------------------------------------------------------
>> > ---------------
>> > > TypeError                                 Traceback (most recent call
>> > last)
>> > > <ipython-input-3-1471f5d738e8> in <module>()
>> > > ----> 1 n.floor(n.linspace(0,5,7), dtype=n.int <http://n.int>)
>> > >
>> > > TypeError: No loop matching the specified signature and casting
>> > > was found for ufunc floor
>> > >
>> > > In [4]: n.__version__
>> > > Out[4]: '1.11.0'
>> > > """
>> > >
>> > > Is this the expected behavior?
>> >
>> > Yes. There is no floor function for integers.
>> >
>> > The dtype argument specified not only the return type, but the type the
>> > calculation is done in as well. floor() only exists, and only makes
>> > sense, for floats. (You can use floor(a, dtype='f4') and so on to insist
>> > on floats of a different width)
>>
>
> +1 for specifying a dtype in np.floor and np.ceil.
>
> Now it is pretty odd that np.floor and np.ceil results in an integer,
> except for that it doesn't. it returns a float with all zeros as the
> decimals. It would be very useful to be able to specify the dtype at 'int'.
> I frequently use floor or ceil to determine the indices of an array, but
> now need to convert to integers in addition to floor and ceil.
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
>


-- 
Renato Fabbri
GNU/Linux User #479299
labmacambira.sourceforge.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170927/79f68a71/attachment.html>


More information about the NumPy-Discussion mailing list