d3array
inline fun <T : Any> Multik.d3array( sizeD1: Int, sizeD2: Int, sizeD3: Int, noinline init: (Int) -> T): D3Array<T>
Content copied to clipboard
Creates a new 3-dimensions array of the specified (sizeD1, sizeD2, sizeD3) 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.d3array(2, 2, 2) { if (it % 2 == 0) 0 else it * it }
println(ndarray)
/*
[[[0, 1],
[0, 9]],
[[0, 25],
[0, 49]]]
*/
//sampleEnd
}