inclusiverange#

inclusiverange(*args, stretch=False, **kwargs)[source]#

Like numpy.arange()/numpy.linspace, but includes the start and stop points. Accepts 0-3 args, or the kwargs start, stop, step.

In most cases, equivalent to np.linspace(start, stop, int((stop-start)/step)+1).

Parameters:
  • start (float) – value to start at

  • stop (float) – value to stop at

  • step (float) – step size

  • stretch (bool) – if True, adjust the step size to end exactly at stop if needed

  • kwargs (dict) – passed to numpy.linspace()

Examples:

x = sc.inclusiverange(10)        # Like np.arange(11)
x = sc.inclusiverange(3,5,0.2)   # Like np.linspace(3, 5, int((5-3)/0.2+1))
x = sc.inclusiverange(stop=5)    # Like np.arange(6)
x = sc.inclusiverange(6, step=2) # Like np.arange(0, 7, 2)
x = sc.inclusiverange(0, 10, 3) # Like np.arange(0, 10, 3)
x = sc.inclusiverange(0, 10, 3, stretch=True) # Like np.linspace(0,10,int(10/3)+1)
New in version 3.2.0: “stretch” argument