Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer np.rint() Over np.round() for Integer Rounding of Averages #496

Open
dbsi-pinkman opened this issue Mar 19, 2025 · 0 comments
Open

Comments

@dbsi-pinkman
Copy link

seconds=numpy.round(numpy.average(time_list))

In this line:
seconds = numpy.round(numpy.average(time_list))
you're calculating the average of a list of values and then rounding the result to the nearest integer. Since you're rounding to an integer and not specifying any decimal precision, using numpy.rint() is a more efficient and semantically appropriate alternative:
seconds = numpy.rint(numpy.average(time_list))
If an integer result is specifically needed (not a float like 60.0), you can also cast it:
seconds = int(numpy.rint(numpy.average(time_list)))
np.rint() is lighter and faster, as it directly wraps the C standard library’s rint() function with minimal overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant