perturb#

perturb(*args, n=1, span=0.5, randseed=None, normal=False)[source]#

Define an array of numbers uniformly perturbed with a mean of 1.

Note: if called with a single argument, this is intepreted as “span”, not “n”.

Parameters:
  • n (int) – number of points; or an array to perturb

  • span (float) – width of distribution on either side of 1 (or standard deviation if normal=True)

  • randseed (int) – seed passed to the reseed Numpy’s random number generator

  • normal (bool) – whether to use a normal distribution instead of uniform

Example:

sc.perturb() # Returns a random number on (0.5, 1.5)
sc.perturb(0.1) # Returns a random number on (0.9, 1.1)
sc.perturb(5, 0.3) # Returns e.g. array([0.73852362, 0.7088094 , 0.93713658, 1.13150755, 0.87183371])
sc.perturb([1,2,3], 0.1, normal=True) # Returns e.g. array([1.03574377, 2.00286363, 3.53437126])
New in version 3.0.0: Uses a separate random number stream
New in version 3.2.1: Allows use with a single argument; allows “n” to be an array