from math import sqrt def multipl(a,b): sumofab=0.0 for i in range(len(a)): temp=a[i]*b[i] sumofab+=temp return sumofab def corrcoef(x,y): n=len(x) #求和 sum1=sum(x) sum2=sum(y) #求乘积之和 sumofxy=multipl(x,y) #求平方和 sumofx2 = sum([pow(i,2) for i in x]) sum
template <class T1, class T2>double Pearson(std::vector<T1> &inst1, std::vector<T2> &inst2) { if(inst1.size() != inst2.size()) { std::cout<<"the size of the vectors is not the same\n"; return 0; } size_t n=inst1.s
利用字节位操作如何判断一个整数的二进制是否含有至少两个连续的1 的方法有多种,大家第一反应应该想到的是以下的第一种方法. 方法一:从头到尾遍历一遍每一位即可找出是否有连续的1存在 这个方法是最普遍的.第一感觉就能想到的方法,下面我们看一下它的具体实现: Python代码: def method_1(n) : last_is_one = False this_is_one = False while n > 0: this_is_one = n % 2 if this_is_one and las