If I want to determine the smallest values in the rows of A::Matrix
it’s as easy as:
min = minimum(A, dims=2)
However, if I have a Vector
of SVector{3}
's it’s a bit more complicated. This
using StaticArrays
function test()
n = 10
A = [SVector{3}(rand(3)) for i = 1:n]
min = minimum(A)
return min
end
min = test()
Will give me the element of A
which has the smallest component instead of comparing all SVector{3}'s and return the smallest 1st, 2nd and 3rd components.
What actually gives me what I want is this:
function test2()
n = 10
A = [SVector{3}(rand(3)) for i = 1:n]
minX = minimum(a[1] for a in A)
minY = minimum(a[2] for a in A)
minZ = minimum(a[3] for a in A)
return SVector{3}(minX, minY, minZ)
end
min = test2()
Is there a more convenient way to do this without calling minimum
3 times? Other than a for loop that is, because test2()
and a for-loop generalisation walks through A
multiple times.