Reference · Vectors
vec.linspace
vec.linspace(num, num, int=, bool=) -> listWhat it does
n evenly spaced floats from start to stop, both included; n is 50 when left out.
With endpoint false, stop is left out and the step is (stop - start) / n, so the
list is the first n of n + 1 points. The last item is exactly stop when the
endpoint is included.
Examples
print(vec.linspace(0, 1, 5))print(vec.linspace(0, 1, 5, false))print(vec.linspace(0, 10, 3))print(len(vec.linspace(0, 1)))[0.0, 0.25, 0.5, 0.75, 1.0][0.0, 0.2, 0.4, 0.6000000000000001, 0.8][0.0, 5.0, 10.0]50Edge cases
startabovestopcounts down.nof 0 is the empty list;nof 1 is[start];nof 2 is[start, stop].- The same
startandstoprepeats itntimes. - The items between are computed as
start + i * step, so they carry float rounding (0.6000000000000001); only the ends are exact. nullasnorendpointmeans the default.
print(vec.linspace(1, 0, 3))print(vec.linspace(0, 1, 0), vec.linspace(0, 1, 1), vec.linspace(0, 1, 2))print(vec.linspace(5, 5, 3))print(vec.linspace(0, 0.3, 4))print(vec.linspace(0, 1, 3, null))[1.0, 0.5, 0.0][] [0.0] [0.0, 1.0][5.0, 5.0, 5.0][0.0, 0.09999999999999999, 0.19999999999999998, 0.3][0.0, 0.5, 1.0]Errors
A negative n, or one over ten million, is a runtime error, not an error value; so are
an n that is not an int and a start or stop that is not a number.
print(vec.linspace(0, 1, -1))line 1: `vec.linspace`: -1 is not a count from 0 to 10000000print(vec.linspace(0, 1, 2.5))line 1: `vec.linspace` expects an int as argument 3, got floatChaining
A grid of x values to evaluate a function on, for a chart:
let xs = vec.linspace(0, math.pi, 5)print(xs | map(math.sin) | vec.round(3))print(vec.linspace(0, 100, 5, false) | vec.round)[0.0, 0.707, 1.0, 0.707, 0.0][0, 20, 40, 60, 80]See also
vec.arange, range, vec.zeros, vec.full
Thread 0 posts
On vec.linspace(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo