Is there any N-Dimensional Array library? I need it for Scientific Purposes


Hello everyone,

in my study program, I frequently need to use arrays of 2, 3 or sometimes even 4 or more dimensions. Is there any easy way to create them? For my purpose, even a third party library is fine. For example, to create an int array of three dimensions data[10][20[30],I am looking for something like: val data = Vector(ndimension = (10, 20, 30), default = 0). It is easy enough.

I heard that Kotlin is supported in ACM ICPC but I doubt that anyone would use it because of this same reason even though it can do everything Java can with a nicer syntax.

Thank you.


If you need to only create 3d-array, you do not need library for that, just add a function, creating it:

fun array3D(dim1: Int, dim2: Int, dim3: Int, def: (Int,Int,Int) -> Double = {_,_,_ ->0.0})
  : Array<Array<Array<Double>>>{
    return Array(dim1){ i ->
         Array(dim2){ j ->
             Array(dim3){ k -> def(i, j, k) }

For larger ndarrays, I would not recommend using java arrays due to memory allocation issues and cumbersome kotlin treatment of multi-dimensional arrays.

I think, it is time to seriously start developing kotlin math extension library. I’ve initialized the repository and will shortly move my existing code there. I currently have a very tight schedule, so I will welcome any help with the project.


There is one from Romain Guy:

Might have synergies.


I think it is quite different. It is made for 3d rendering, not for scientific purposes. I am wrapping commons math with kotlin wrappers. Maybe it is also good idea to have a small kotlin-only api without including additional dependency.


Sure it is a good idea to have it, but still not yet available at the moment :frowning: