Functions Index :: A :: ArrayRange

[<< up one level]


array :: core


ArrayRange(val start, val end, val "step", int "npoints")


Returns an array with values covering the range [start..end] either with a specified step or with a specified number of points (when the optional npoints parameter is specified).


start: The start value of the range (int or float).

end: The end value of the range (int or float).

"step" (Optional, defaults to 1): The step value to add in each successive step until end is reached.

"npoints" (Optional): The number of points (array elements) to divide the specified range ([start..end]).

Notes and conditions on arguments relations:

1] step and npoints cannot be specified together (the function will throw an error).

2] When step is defined and the values of start and step are such that end cannot exactly be reached by succesively addind step to start then the maximum valid value < end will be the last element of the returned array.

This is of importance when float values are used, since then small approximation errors inherent to float arithmetic may result in arrays with one less element than the number expected by the arguments. If this happens, add a small number to end (for example 0.0001) in order to get the expected number of array elements.


a1 = ArrayRange(0, 10)

# a1 == "0,1,2,3,4,5,6,7,8,9,10"

a2 = ArrayRange(0, 10, 2)

# a2 == "0,2,4,6,8,10"

a3 = ArrayRange(0, 10, 3)

# a3 == "0,3,6,9"

a4 = ArrayRange(0, 10, npoints=5)

# a4 == "0,2.5,5.0,7.5,10.0"


[<< top]