Skip to content

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

Closed as not planned
@SaFE-APIOpt

Description

@SaFE-APIOpt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions