Generating sequence of numbers in Python (curved) Generating sequence of numbers in Python (curved) numpy numpy

Generating sequence of numbers in Python (curved)


There are bunch of nonlinear function that can be used for the task (some are listed here). Below is a simple exponential function to generate nonlinear array between two numbers. You can control curvature in the function:

import numpy as npdef nonlinspace(start, stop, num):    linear = np.linspace(0, 1, num)    my_curvature = 1    curve = 1 - np.exp(-my_curvature*linear)    curve = curve/np.max(curve)   #  normalize between 0 and 1    curve  = curve*(stop - start-1) + start    return curvearr = nonlinspace(7, 21, 10)#rounded result : [ 7., 9.16, 11.1, 12.83, 14.38, 15.77, 17.01, 18.12, 19.11, 20.]