go - How to find the dimensions of a (2,3 or if possible an n)dimensional slice in golang and verify if its a matrix? -


for example : [][]float64{{11, 5, 14, 1}, {11, 5, 14, 1}} has dimensions [2,4].

if passed function efficient way find dimension here?

thanks

the outer dimension len(x) x slice of slices pass function (your example [][]float64{{11, 5, 14, 1}, {11, 5, 14, 1}}). however, inner dimensions not guaranteed equal have go through each element , check len have.

if have guarantee each element of x has same number of elements, find len(x[0]) if len(x) > 0.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -