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
Post a Comment