Created
December 9, 2021 21:51
-
-
Save cossio/9c081a3033afe27c90e22327b2256a80 to your computer and use it in GitHub Desktop.
argmax of `A` over its first `N` dimensions and drops them. By default `N = 1`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
argmax_first(A, Val(N) = Val(1)) | |
argmax of `A` over its first `N` dimensions and drops them. By default `N = 1`. | |
""" | |
function argmax_first(A::AbstractArray, ::Val{N} = Val(1)) where {N} | |
dims = tuplen(Val(N)) | |
argmax_(A; dims=dims) | |
end | |
@testset "argmax_first" begin | |
@inferred argmax_first(randn(3,2,4)) | |
@test size(argmax_first(randn(3,2,4))) == (2,4) | |
A = [3 4; 1 2] | |
i = argmax_first(A) | |
@test A[i] == [3, 4] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment