randround#

randround(x)[source]#

Round a float, list, or array probabilistically to the nearest integer. Works for both positive and negative values.

Adapted from:

https://stackoverflow.com/questions/19045971/random-rounding-to-integer-in-python

Parameters:

x (int, list, arr) – the floating point numbers to probabilistically convert to the nearest integer

Returns:

Array of integers

Example:

sc.randround(np.random.randn(8)) # Returns e.g. array([-1,  0,  1, -2,  2,  0,  0,  0])
New in version 1.0.0.
New in version 3.0.0: allow arrays of arbitrary shape