Phyton Why is there a difference between round(x) and round(np.float64(x))? python the difference between two dates,python the difference between

From what i understand, 2.675 and numpy.float64(2.675) are both the same number. However, round(2.675, 2) gives 2.67, while round(np.float64(2.675), 2) gives 2.68. Why does this happen?

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
Answer:1



  1. python the difference between two dates
  2. python the difference between fit_transform and transform
  3. python find the difference between two lists
  4. python get the difference between two lists
  5. python find the difference between two strings
  6. python calculate the difference between two dates
  7. python find the difference between two numbers
  8. python find the difference between two dates
  9. python get the difference between two dates
  10. python get the difference between two strings
  11. python get the difference between two dictionaries
  12. python find the difference between two sets
  13. python what's the difference between a tuple and a list
  14. python find the difference between two times
  15. python print the difference between two strings
  16. python get the difference between two times
  17. python get the difference between two numbers
  18. python print the difference between two lists
  19. python find the difference between two files
  20. python get the difference between two files

Very specific question (I hope): What are the differences between the following three codes? (I expect it to be only that the first does not wait for the child process to be finished, while the ...

Very specific question (I hope): What are the differences between the following three codes? (I expect it to be only that the first does not wait for the child process to be finished, while the ...

I have 2 dataframes: one (A) with some whitelist hostnames in regex form (ie (.*)microsoft.com, (*.)go.microsoft.com...) and another (B) with actual full hostnames of sites. I want to add a new ...

I have 2 dataframes: one (A) with some whitelist hostnames in regex form (ie (.*)microsoft.com, (*.)go.microsoft.com...) and another (B) with actual full hostnames of sites. I want to add a new ...