문제
저는 Erlang을 처음 접했기 때문에 저의 순진함을 용서해주세요.
다른 언어로 작성한 함수를 다시 작성하려고 합니다.그 중 하나가 Jaccard 비트 인덱스입니다.
Python Haskell과 Clojure에서는 다음과 같이 작동합니다.
xs = [1,1,0,0,1,1,0,0,1,1,0,0]
ys = [1,0,1,0,1,0,1,0,1,0,1,0]
# python 3.X
def jaccard_bit_index(A,B):
i = sum(map(operator.mul ,A,B))
return i / (sum(A) + sum(B) - i)
-- haskell
jaccrd_bit_index a b =
count / ((sum a) + (sum b) - count)
where
count = sum $ zipWith (*) a b
%% clojure
(defn jaccard-bit-index [a b]
(let [binarycount (apply + (map * a b))]
(/ binarycount
(- (+ (apply + a) (apply + b))
binarycount))))
내 문제는 내가 Erlang에 대해서만 알고 있다는 것입니다.
map(Fun, List1) -> List2
그리고 그 일을 할 때마다 나는 다음과 비슷한 것을 사용했습니다:
map(Fun, List1, List2) -> List3
해결책
나는 당신이 검색하는 것이 무엇인지 확신합니다 zipwith
에서 기능 list
모듈(http://www.erlang.org/doc/man/lists.html).이는 다음과 유사합니다. zipWith
사용했던 haskell 함수의 유형은 다음과 같습니다.
zipwith(Combine, List1, List2) -> List3
아마도 다음과 같은 것을 사용할 것입니다.
Count = lists:sum(lists:zipwith(fun(X, Y) -> X*Y end, A, B))
제휴하지 않습니다 StackOverflow