round
ast
none at gmail.com
Thu Jun 7 07:09:18 EDT 2018
Hi
round is supposed to provide an integer when
called without any precision argument.
here is the doc:
>>> help(round)
round(number[, ndigits]) -> number
Round a number to a given precision in decimal digits (default 0 digits).
This returns an int when called with one argument, otherwise the
same type as the number
but in some circumstances it provides a float
import numpy as np
M = np.array([[0, 9],[2, 7]], dtype=int)
np.linalg.det(M)
-18.000000000000004
round(np.linalg.det(M))
-18.0 # i was expecting an integer -18, not a float
# same problem with np.round
np.round(np.linalg.det(M))
-18.0
More information about the Python-list
mailing list