Map erlang映射函数
我是新来二郎的,所以请原谅我的天真 我正在尝试重新编写用其他语言编写的函数。其中之一是jaccard位索引 在python haskell和clojure中,它的工作原理如下:Map erlang映射函数,map,erlang,arity,Map,Erlang,Arity,我是新来二郎的,所以请原谅我的天真 我正在尝试重新编写用其他语言编写的函数。其中之一是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
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(乐趣,列表1)->List2
每次我做这件事之前,我都会使用类似的东西:
map(Fun,List1,List2)->List3
我打赌您正在搜索的是模块中的zipwith
函数(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))
我打赌您正在搜索的是列表
模块中的zipwith
函数(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))
那看起来正是我要找的!那看起来正是我要找的!