Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php get cosine sim

function dotp($arr1, $arr2){
     return array_sum(array_map(create_function('$a, $b', 'return $a * $b;'), $arr1, $arr2));
}
function cosineSim($arr1, $arr2){
	return dotp($arr1,$arr2)/sqrt(dotp($arr1,$arr1)*dotp($arr2,$arr2));
}
 
PREVIOUS NEXT
Tagged: #php #cosine #sim
ADD COMMENT
Topic
Name
7+7 =