Created
December 9, 2021 21:51
-
-
Save cossio/9c081a3033afe27c90e22327b2256a80 to your computer and use it in GitHub Desktop.
Revisions
-
cossio created this gist
Dec 9, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ """ 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