linspace
Creates a 1D array of exactly num evenly spaced values over the closed interval [start, stop]. Unlike arange, both endpoints are included and the number of points is specified directly rather than a step size.
Signatures
inline fun <reified T : Number> Multik.linspace(
start: Int, stop: Int, num: Int = 50
): D1Array<T>
inline fun <reified T : Number> Multik.linspace(
start: Double, stop: Double, num: Int = 50
): D1Array<T>
Parameters
Parameter | Type | Default | Description |
|---|---|---|---|
|
| — | Start of the interval (inclusive). |
|
| — | End of the interval (inclusive). |
|
|
| Number of values to generate. Must be > 0. |
Returns: D1Array<T> with num evenly spaced values from start to stop inclusive.
Example
val a = mk.linspace<Double>(0, 1, 5)
// [0.0, 0.25, 0.5, 0.75, 1.0]
val b = mk.linspace<Float>(0.0, 10.0, 3)
// [0.0, 5.0, 10.0]
linspace vs arange
|
| |
|---|---|---|
Endpoint | Included ( | Excluded ( |
Control | Specify number of points | Specify step size |
Precision | Last element guaranteed to equal | May accumulate floating-point drift |
28 February 2026