@@ -824,6 +824,17 @@ function findnz{T}(A::AbstractMatrix{T})
824
824
return (I, J, NZs)
825
825
end
826
826
827
+ """
828
+ findmax(itr) -> (x, index)
829
+
830
+ Returns the maximum element and its index.
831
+ The collection must not be empty.
832
+
833
+ ```jldoctest
834
+ julia> findmax([8,0.1,-9,pi])
835
+ (8.0,1)
836
+ ```
837
+ """
827
838
function findmax (a)
828
839
if isempty (a)
829
840
throw (ArgumentError (" collection must be non-empty" ))
@@ -842,6 +853,17 @@ function findmax(a)
842
853
return (m, mi)
843
854
end
844
855
856
+ """
857
+ findmin(itr) -> (x, index)
858
+
859
+ Returns the minimum element and its index.
860
+ The collection must not be empty.
861
+
862
+ ```jldoctest
863
+ julia> findmax([8,0.1,-9,pi])
864
+ (-9.0,3)
865
+ ```
866
+ """
845
867
function findmin (a)
846
868
if isempty (a)
847
869
throw (ArgumentError (" collection must be non-empty" ))
@@ -860,16 +882,87 @@ function findmin(a)
860
882
return (m, mi)
861
883
end
862
884
885
+ """
886
+ indmax(itr) -> Integer
887
+
888
+ Returns the index of the maximum element in a collection.
889
+ ```jldoctest
890
+ julia> indmax([8,0.1,-9,pi])
891
+ 1
892
+ ```
893
+ """
863
894
indmax (a) = findmax (a)[2 ]
895
+
896
+ """
897
+ indmin(itr) -> Integer
898
+
899
+ Returns the index of the minimum element in a collection.
900
+ ```jldoctest
901
+ julia> indmin([8,0.1,-9,pi])
902
+ 3
903
+ ```
904
+ """
864
905
indmin (a) = findmin (a)[2 ]
865
906
866
907
# similar to Matlab's ismember
867
- # returns a vector containing the highest index in b for each value in a that is a member of b
908
+ """
909
+ indexin(a, b)
910
+
911
+ Returns a vector containing the highest index in `b` for
912
+ each value in `a` that is a member of `b` . The output
913
+ vector contains 0 wherever `a` is not a member of `b`.
914
+
915
+ ```jldoctest
916
+ julia> a = ['a', 'b', 'c', 'b', 'd', 'a'];
917
+
918
+ julia> b = ['a','b','c']
919
+
920
+ julia> indexin(a,b)
921
+ 6-element Array{Int64,1}:
922
+ 1
923
+ 2
924
+ 3
925
+ 2
926
+ 0
927
+ 1
928
+
929
+ julia> indexin(b,a)
930
+ 3-element Array{Int64,1}:
931
+ 6
932
+ 4
933
+ 3
934
+ ```
935
+ """
868
936
function indexin (a:: AbstractArray , b:: AbstractArray )
869
937
bdict = Dict (zip (b, 1 : length (b)))
870
938
[get (bdict, i, 0 ) for i in a]
871
939
end
872
940
941
+ """
942
+ findin(a, b)
943
+
944
+ Returns the indices of elements in collection `a` that appear in collection `b`.
945
+
946
+ ```jldoctest
947
+ julia> a = collect(1:3:15)
948
+ 5-element Array{Int64,1}:
949
+ 1
950
+ 4
951
+ 7
952
+ 10
953
+ 13
954
+
955
+ julia> b = collect(2:4:10)
956
+ 3-element Array{Int64,1}:
957
+ 2
958
+ 6
959
+ 10
960
+
961
+ julia> findin(a,b) # 10 is the only common element
962
+ 1-element Array{Int64,1}:
963
+ 4
964
+ ```
965
+ """
873
966
function findin (a, b)
874
967
ind = Array {Int,1} (0 )
875
968
bset = Set (b)
0 commit comments