Does anyone have a handy link for 3d <> 1d a...
# mathematics
b
Does anyone have a handy link for 3d <> 1d array index conversions? Google only surfaces the common 2d<>1d... I basically need to get x,y,z coordinates from a given 1d array index
In case anyone else looks for it:
Copy code
val z: Int = i / (width * height)
    val y: Int = (i - z * width * height) / width
    val x: Int = i - width * (y + height * z)
a
What you probablywant is a strided arrays. They are used both in Multik and KMath. Here is a default implementaion: https://github.com/mipt-npm/kmath/blob/8974164ec05dcfa5feab830cfa8223291e1dbb79/km[…]e/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeIndexer.kt
There a different ways to implement strides (row-wise, column-wise, etc.). You need to choose one.