dnarray
inline fun <T : Any> Multik.dnarray( sizeD1: Int, sizeD2: Int, sizeD3: Int, sizeD4: Int, vararg dims: Int, noinline init: (Int) -> T): NDArray<T, DN>
Content copied to clipboard
Creates a new 4-dimensions array of the specified (sizeD1, sizeD2, sizeD3, sizeD4, dims) shape, where each element is calculated by calling the specified init function.
The function init is called for each array element sequentially starting from the first one. It should return the value for an array element given its index.
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.dnarray(1, 2, 1, 2, 1, 2) { kotlin.math.PI * it }
println(ndarray)
/*
[[[[[[0.0, 3.141592653589793]],
[[6.283185307179586, 9.42477796076938]]]],
[[[[12.566370614359172, 15.707963267948966]],
[[18.84955592153876, 21.991148575128552]]]]]]
*/
//sampleEnd
}
inline fun <T : Any, D : Dimension> Multik.dnarray(shape: IntArray, noinline init: (Int) -> T): NDArray<T, D>
Content copied to clipboard
Returns a new array with the specified shape, where each element is calculated by calling the specified init function.
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(1, 1, 2, 1, 1)
val ndarray = mk.dnarray<Double, DN>(dims) { kotlin.math.PI * it }
println(ndarray)
/*
[[[[[0.0]],
[[3.141592653589793]]]]]
*/
//sampleEnd
}