Let’s say I want to find the position of the maximum element in a 2D array. The closest I found: [indmax] (Location of minimum in Julia - Stack Overflow) or findmax,
which does not work as expected with arrays having more than 1D:
julia> x = [8 -4 3; 1 10 -1; 3 12 4]
3×3 Array{Int64,2}:
8 -4 3
1 10 -1
3 12 4
julia> indmax(x)
6
julia> findmax(x)
(12,6)
As position, it returns one integer, 6. Of course, from this, we can compute the 2D coordinate (3,2). But, wouldn’t it be nice to see the 2D coordinate as output directly? Is it worth reporting an issue?
[details=Click to expand previous comment]which do not work with array having more than 1D:
julia> x = [[8 -4 3], [12 10 -1]]
2-element Array{Array{Int64,2},1}:
[8 -4 3]
[12 10 -1]
julia> indmax(x)
ERROR: MethodError: no method matching isless(::Array{Int64,2}, ::Array{Int64,2})
in findmax(::Array{Array{Int64,2},1}) at .\array.jl:1233
in indmax(::Array{Array{Int64,2},1}) at .\array.jl:1281
julia> findmax(x)
ERROR: MethodError: no method matching isless(::Array{Int64,2}, ::Array{Int64,2})
in findmax(::Array{Array{Int64,2},1}) at .\array.jl:1233
- Is this worth reporting a bug? Or, I misunderstood anything?
- For 1D array, both
indmaxandfindmaxreturn a 2 element array, the second element being the position. Depending on the situation, which may not be sufficient (e.g., to find the frequency of the maximum element; find the maximum element along one particular axis).Numpyprovides a lot of functions:argmax,maxoramax,maximum,argsortetc. Wouldn’t it be nice to have these features?[/details]