[Numpy-discussion] Output type of round is inconsistent with python built-in

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Feb 26 18:57:50 EST 2020


On Wed, Feb 26, 2020 at 6:09 PM Robert Kern <robert.kern at gmail.com> wrote:

> On Wed, Feb 26, 2020 at 5:27 PM <josef.pktd at gmail.com> wrote:
>
>> great another object array
>>
>> np.asarray([round(x_i.item()) for x_i in np.array([1, 2.5, 2e20, 2e200])])
>> array([1, 2, 200000000000000000000,
>>
>>  199999999999999993946624442502072331894900655091004725296483501900693696871108151068392676809412503736055024831947764816364271468736556969278770082094479755742047182133579963622363626612334257709776896],
>>       dtype=object)
>>
>>
>> I would rather have numpy consistent with numpy than with python
>>
>
> Since round() (and the __round__() interface) is part of Python and not
> numpy, there is nothing in numpy to be consistent with. We only implement
> __round__() for the scalar types.
>


Maybe I misunderstand

I'm using np.round a lot. So maybe it's a question whether and how it will
affect np.round.

Does the following change with the proposal?

np.round(np.array([1, 2.5, 2e20, 2e200]))
array([1.e+000, 2.e+000, 2.e+020, 2.e+200])

np.round(np.array([1, 2.5, 2e20, 2e200])).astype(int)
array([          1,           2, -2147483648, -2147483648])

np.round(np.array([2e200])[0])
2e+200

np.round(2e200)
2e+200

round(2e200)
199999999999999993946624442502072331894900655091004725296483501900693696871108151068392676809412503736055024831947764816364271468736556969278770082094479755742047182133579963622363626612334257709776896

Josef
"around 100" sounds like "something all_close(100)"


>
> --
> Robert Kern
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20200226/40c7dd6e/attachment.html>


More information about the NumPy-Discussion mailing list