identity

inline fun <T : Any> Multik.identity(n: Int): D2Array<T>

Returns the identity array.

Return

D2Array.

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 identNDArray = mk.identity<Long>(3)
println(identNDArray)
/*
[[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]
 */ 
   //sampleEnd
}

Parameters

n

number of rows and columns.


fun <T> Multik.identity(n: Int, dtype: DataType): D2Array<T>

Returns the identity array.

Note: Generic type of elements must match dtype.

Return

D2Array

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 identNDArray = mk.identity<Long>(3, DataType.LongDataType)
println(identNDArray)
/*
[[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]
 */ 
   //sampleEnd
}

Parameters

n

number of rows and columns.

dtype

array type.