ones

inline fun <T : Any> Multik.ones(dim1: Int): D1Array<T>

Returns a new ones array of 1 dim of type T with dim1 size.

Samples

import org.jetbrains.kotlinx.multik.api.*
import org.jetbrains.kotlinx.multik.ndarray.data.D2
import org.jetbrains.kotlinx.multik.ndarray.data.D3
import org.jetbrains.kotlinx.multik.ndarray.data.DN
import org.jetbrains.kotlinx.multik.ndarray.data.DataType
import kotlin.test.Test
fun main() { 
   //sampleStart 
   val ndarray = mk.ones<Int>(5)
println(ndarray) // [1, 1, 1, 1, 1] 
   //sampleEnd
}

inline fun <T : Any> Multik.ones(dim1: Int, dim2: Int): D2Array<T>

Returns a new ones array of 2 dim of type T with (dim1, dim2) shape.

Samples

import org.jetbrains.kotlinx.multik.api.*
import org.jetbrains.kotlinx.multik.ndarray.data.D2
import org.jetbrains.kotlinx.multik.ndarray.data.D3
import org.jetbrains.kotlinx.multik.ndarray.data.DN
import org.jetbrains.kotlinx.multik.ndarray.data.DataType
import kotlin.test.Test
fun main() { 
   //sampleStart 
   val ndarray = mk.ones<Float>(2, 2)
println(ndarray)
/*
 [[1.0, 1.0],
  [1.0, 1.0]]
 */ 
   //sampleEnd
}

inline fun <T : Any> Multik.ones(    dim1: Int,     dim2: Int,     dim3: Int): D3Array<T>

Returns a new ones array of 3 dim of type T with (dim1, dim2, dim3) shape.

Samples

import org.jetbrains.kotlinx.multik.api.*
import org.jetbrains.kotlinx.multik.ndarray.data.D2
import org.jetbrains.kotlinx.multik.ndarray.data.D3
import org.jetbrains.kotlinx.multik.ndarray.data.DN
import org.jetbrains.kotlinx.multik.ndarray.data.DataType
import kotlin.test.Test
fun main() { 
   //sampleStart 
   val ndarray = mk.ones<Double>(2, 2, 2)
println(ndarray)
/*
 [[[1.0, 1.0],
   [1.0, 1.0]],

  [[0.0, 0.0],
   [0.0, 0.0]]]
 */ 
   //sampleEnd
}

inline fun <T : Any> Multik.ones(    dim1: Int,     dim2: Int,     dim3: Int,     dim4: Int): D4Array<T>

Returns a new ones array of 4 dim of type T with (dim1, dim2, dim3, dim4) shape.

Samples

import org.jetbrains.kotlinx.multik.api.*
import org.jetbrains.kotlinx.multik.ndarray.data.D2
import org.jetbrains.kotlinx.multik.ndarray.data.D3
import org.jetbrains.kotlinx.multik.ndarray.data.DN
import org.jetbrains.kotlinx.multik.ndarray.data.DataType
import kotlin.test.Test
fun main() { 
   //sampleStart 
   val ndarray = mk.ones<Double>(2, 1, 2, 1)
println(ndarray)
/*
 [[[[1.0],
    [1.0]]],


  [[[1.0],
    [1.0]]]]
 */ 
   //sampleEnd
}

inline fun <T : Any> Multik.ones(    dim1: Int,     dim2: Int,     dim3: Int,     dim4: Int,     vararg dims: Int): NDArray<T, DN>

Returns a new ones array of N dim of type T with (dim1, dim2, dim3, dim4, dims) shape.

Samples

import org.jetbrains.kotlinx.multik.api.*
import org.jetbrains.kotlinx.multik.ndarray.data.D2
import org.jetbrains.kotlinx.multik.ndarray.data.D3
import org.jetbrains.kotlinx.multik.ndarray.data.DN
import org.jetbrains.kotlinx.multik.ndarray.data.DataType
import kotlin.test.Test
fun main() { 
   //sampleStart 
   val ndarray = mk.ones<Double>(1, 1, 1, 2, 2)
println(ndarray)
/*
 [[[[[1.0, 1.0],
     [1.0, 1.0]]]]]
 */ 
   //sampleEnd
}

fun <T, D : Dimension> Multik.ones(dims: IntArray, dtype: DataType): NDArray<T, D>

Returns a new ones array of N dim of type T with specify shape.

Samples

import org.jetbrains.kotlinx.multik.api.*
import org.jetbrains.kotlinx.multik.ndarray.data.D2
import org.jetbrains.kotlinx.multik.ndarray.data.D3
import org.jetbrains.kotlinx.multik.ndarray.data.DN
import org.jetbrains.kotlinx.multik.ndarray.data.DataType
import kotlin.test.Test
fun main() { 
   //sampleStart 
   val dims = intArrayOf(3, 2)
val ndarray = mk.ones<Float, D2>(dims, DataType.FloatDataType)
println(ndarray)
/*
 [[1.0, 1.0],
  [1.0, 1.0],
  [1.0, 1.0]]
 */ 
   //sampleEnd
}