ones
Creates an array of the given shape filled with ones. Overloads are available for 1D through 4D, N-dimensional (5+), and generic shape-based creation.
Signatures
inline fun <reified T : Any> Multik.ones(dim1: Int): D1Array<T>
inline fun <reified T : Any> Multik.ones(dim1: Int, dim2: Int): D2Array<T>
inline fun <reified T : Any> Multik.ones(dim1: Int, dim2: Int, dim3: Int): D3Array<T>
inline fun <reified T : Any> Multik.ones(dim1: Int, dim2: Int, dim3: Int, dim4: Int): D4Array<T>
inline fun <reified T : Any> Multik.ones(
dim1: Int, dim2: Int, dim3: Int, dim4: Int, vararg dims: Int
): NDArray<T, DN>
Generic with DataType
fun <T, D : Dimension> Multik.ones(dims: IntArray, dtype: DataType): NDArray<T, D>
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Axis sizes. Must be positive. |
|
| Additional axis sizes beyond the fourth. |
|
| Element type (for the non-reified overload). |
Returns: NDArray of the given shape filled with ones.
Example
val v = mk.ones<Double>(5) // [1.0, 1.0, 1.0, 1.0, 1.0]
val m = mk.ones<Int>(2, 3) // [[1, 1, 1], [1, 1, 1]]
val t = mk.ones<Float>(2, 3, 4) // shape (2, 3, 4), all 1.0f
28 February 2026