Reputation: 1474
The output of findmax(x, dims=2)
has some strange types. How can I normalize them?
julia> x = [10 20; 40 30]
2×2 Matrix{Int64}:
10 20
40 30
julia> (maxvalue, maxindex) = findmax(x, dims=2)
([20; 40;;], CartesianIndex{2}[CartesianIndex(1, 2); CartesianIndex(2, 1);;])
julia> maxvalue
2×1 Matrix{Int64}:
20
40
julia> maxindex
2×1 Matrix{CartesianIndex{2}}:
CartesianIndex(1, 2)
CartesianIndex(2, 1)
I want instead:
julia> maxvalue
2-element Vector{Int64}:
20
40
julia> maxindex
2-element Vector{Int64}:
2
1
Upvotes: 1
Views: 139
Reputation: 69899
Is this what you want?
julia> findmax.(eachrow(x))
2-element Vector{Tuple{Int64, Int64}}:
(20, 2)
(40, 1)
alternatively you can index into CartesianIndex
:
julia> getindex.(maxindex, 2)
2×1 Matrix{Int64}:
2
1
Upvotes: 1