What is wrong with this python function from “Programming Collective Intelligence”?

后端 未结 4 1026
梦如初夏
梦如初夏 2021-01-06 07:31

This is the function in question. It calculates the Pearson correlation coefficient for p1 and p2, which is supposed to be a number between -1 and 1.

When I use this

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 07:39

    Integer division is confusing it. It works if you make n a float:

    n=float(len(si))
    

提交回复
热议问题