Из того, что я понимаю, 2.675 и numpy.float64 (2.675) - это одно и то же число.Тем не менее, раунд (2,675, 2) дает 2,67, а раунд (np.float64 (2,675), 2) дает 2,68.Почему это происходит?
import numpy as np
from decimal import Decimal
x = 2.675
np_x = np.float64(x)
type(x) # float
Decimal(x) # Decimal('2.67499999999999982236431605997495353221893310546875')
Decimal(np_x) # Decimal('2.67499999999999982236431605997495353221893310546875')
x == np_x # True
# This is the bit that bothers me
round(x, 2) # 2.67
round(np_x, 2) # 2.68
# Using numpy's round gives 2.68 for both the numpy float as well as the Python built-in float...
np.round(x, 2) # 2.68
np.round(np_x, 2) # 2.68
# ... but this is because it might be converting the number to a numpy float before rounding
type(np.round(x, 2)) # numpy.float64
# Versions
# Python 3.6.8 running on 64-bit Windows 10
# Numpy 1.16.2