For example : [][]float64{{11, 5, 14, 1}, {11, 5, 14, 1}}
has dimensions [2,4]
.
If this is passed to a function then what is the most efficient way to find the dimension here?
Thanks
For example : [][]float64{{11, 5, 14, 1}, {11, 5, 14, 1}}
has dimensions [2,4]
.
If this is passed to a function then what is the most efficient way to find the dimension here?
Thanks
The outer dimension is just len(x)
where x
is the slice of slices you pass to the function (your example [][]float64{{11, 5, 14, 1}, {11, 5, 14, 1}}
).
However, the inner dimensions are not guaranteed to be equal so you will have to go through each element and check what len
they have.
If you have the guarantee than each element of x
has the same number of elements, just find len(x[0])
if len(x) > 0
.