码迷,mamicode.com
首页 > 编程语言 > 详细

python numpy 机器学习的库使用示例

时间:2014-10-30 17:27:38      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:ar   使用   sp   on   bs   python   res   学习   安装   

安装

sudo yum install numpy


from numpy import *

产生一个数组

random.rand(4,5)

result:

array([[ 0.79056842,  0.31659893,  0.34054779,  0.97328131,  0.32648329],

       [ 0.51585845,  0.70683055,  0.31476985,  0.07952725,  0.80907845],

       [ 0.81623517,  0.61038487,  0.66679161,  0.77412742,  0.03394483],

       [ 0.41758993,  0.54425978,  0.65350633,  0.90397197,  0.72706079]])

产生一个矩阵   

>>> randMat=mat(random.rand(4,4))

>>> randMat.I

matrix([[ 1.72265179,  0.82071484,  0.8218207 , -3.20005387],

        [ 0.60602642, -1.2873106 ,  0.4826296 ,  0.61948819],

        [-1.58733496,  0.1095752 ,  0.88187595,  1.44921728],

        [-0.97809315,  0.25648172, -1.44365489,  2.67132684]])

矩阵相乘:

>>> invRandMat=randMat.I

>>> randMat.I*invRandMat

matrix([[  5.29035012,  -0.37341318,   7.15632948, -12.3615484 ],

        [ -1.10818373,   2.3663151 ,  -0.59195686,  -0.38250032],

        [ -5.48532196,  -0.9754772 ,  -2.56608491,  10.29680078],

        [ -1.85072184,  -0.60594947,  -5.80963009,   8.33265564]])

>>> 

矩阵相加:

>>> randMat.I+invRandMat

matrix([[ 3.44530359,  1.64142968,  1.6436414 , -6.40010773],

        [ 1.21205284, -2.57462121,  0.9652592 ,  1.23897638],

        [-3.17466991,  0.2191504 ,  1.7637519 ,  2.89843456],

        [-1.9561863 ,  0.51296344, -2.88730977,  5.34265368]])

        

        

>>> myEye=randMat.I*invRandMat

>>> myEye-eye(4)

matrix([[  4.29035012,  -0.37341318,   7.15632948, -12.3615484 ],

        [ -1.10818373,   1.3663151 ,  -0.59195686,  -0.38250032],

        [ -5.48532196,  -0.9754772 ,  -3.56608491,  10.29680078],

        [ -1.85072184,  -0.60594947,  -5.80963009,   7.33265564]])

>>> 

eye(4) 创建一个单位矩阵


python numpy 机器学习的库使用示例

标签:ar   使用   sp   on   bs   python   res   学习   安装   

原文地址:http://my.oschina.net/u/1388024/blog/338884

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!