简体   繁体   English

我无法从 numpy 导入/使用 cov() 函数

[英]Im unable to import/use the cov() fonction from numpy

Im trying to use the cov() fonction to simplify my covariance code, but im unable to import it, is it because i dont have the right version of numpy or am i writing the wrong thing???我试图使用 cov() 函数来简化我的协方差代码,但我无法导入它,是因为我没有正确版本的 numpy 还是我写错了东西??? Thanks!谢谢!

liste_revenu_ventes = [1515,6646,13123,65151,11555]
liste_visites_magasin = [123, 554, 1542, 4545, 1244]
covariance_visites_ventes = 0
for i in range(0, len(liste_visites_magasin)) :
    covariance_visites_ventes += (liste_revenu_ventes[i] - moyenne_ventes) * (liste_visites_magasin[i] - moyenne_visites)
covariance_visites_ventes = covariance_visites_ventes / (len(liste_visites_magasin) - 1)
correlation_r = covariance_visites_ventes / (ecart_type_visite * ecart_type_vente) 
print("Le coefficient de corrélation est : ", correlation_r)

In fact you just have to import Numpy to use functions from it, import numpy as np .实际上,您只需要导入 Numpy 即可使用其中的函数, import numpy as np And then if you follow the documentation that you can find here , you will be able to use the covariance function from Numpy.然后,如果您遵循可以在 此处找到的文档,您将能够使用 Numpy 的协方差函数。

Side note: Don't forget to add Numpy to your python environment ( pip install numpy for example).旁注:不要忘记将 Numpy 添加到您的 Python 环境(例如pip install numpy )。

Side note 2: Try to don't use french in your variable names next time to be understood by everyone :) + follow the guidelines gave by funie200 next time.旁注 2:下次尽量不要在变量名中使用法语,以便每个人都能理解:) + 下次遵循 funie200 给出的指导方针。

Have a nice day.祝你今天过得愉快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM