前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python3 安装 numpy 科学库

Python3 安装 numpy 科学库

作者头像
py3study
发布2020-01-03 10:50:32
5970
发布2020-01-03 10:50:32
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
[root@Singapore numpy]# wget https://pypi.python.org/packages/ee/66/7c2690141c520db08b6a6f852fa768f421b0b50683b7bbcd88ef51f33170/numpy-1.14.0.zip
[root@Singapore numpy]# md5sum numpy-1.14.0.zip 
c12d4bf380ac925fcdc8a59ada6c3298  numpy-1.14.0.zip
[root@Singapore numpy]# unzip numpy-1.14.0.zip 
[root@Singapore numpy]# cd numpy-1.14.0
[root@Singapore numpy-1.14.0]# cat INSTALL.rst.txt                                          #安装说明
[root@Singapore numpy-1.14.0]# python3  setup.py build install --prefix /root/python/numpy  #注意安装路径
[root@Singapore numpy-1.14.0]# echo "export PYTHONPATH=/root/python/numpy/lib/python3.6/site-packages" >> ~/.bashrc  #注意安装路径
[root@Singapore numpy-1.14.0]# . ~/.bashrc
[root@Singapore numpy-1.14.0]# echo $?
0
[root@Singapore numpy-1.14.0]# 

写一个线性回归 试一试

代码语言:javascript
复制
[root@Singapore work.dir]# cat SimpleLineRegression.py 
#!/usr/bin/python3

import numpy as np

def fitSLR(x,y):
    n = len(x)
    dinominator = 0
    numerator = 0
    for i in range(0, n):
        numerator += (x[i] - np.mean(x)) * (y[i] - np.mean(y))
        dinominator +=(x[i] - np.mean(x)) ** 2

    print ("numerator:", numerator)
    print ("dinominator", dinominator)
    b1 = numerator/float(dinominator)
    b0 = np.mean(y)/float(np.mean(x))

    return b0, b1

def predict(x, b0, b1):
    return b0 + x*b1

x = [1,3,2,1,3]
y = [14,24,18,17,27]

b0, b1 = fitSLR(x,y)
print ("intercept:", b0, " slope:", b1)

x_test = 6
y_test = predict(6, b0, b1)
print("y_test", y_test)

[root@Singapore work.dir]# ./SimpleLineRegression.py 
numerator: 20.0
dinominator 4.0
intercept: 10.0  slope: 5.0
y_test 40.0
[root@Singapore work.dir]# 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档