Python机器学习之NumPy库初探

  1. 云栖社区>
  2. 博客>
  3. 正文

Python机器学习之NumPy库初探

止于至玄 2017-04-02 11:14:00 浏览726
展开阅读全文
import numpy as np
from numpy import *

#matrix an  overview
mylist=[1,2,3,4,5]
a=10
mymatrix=np.mat(mylist)
print(a*mymatrix)

#special matrix
myzero=np.zeros_like([3,5])
print(myzero)
myzero=np.zeros([3,5])
print(myzero)
myones=np.ones([3,3])
print(myones)
myrand=np.random.rand(3,4)
print(myrand)
myeye=np.eye(3)
print(myeye)

#matrix operation
print(myeye+myones)
print(sum(myones))
mymatrix=np.mat([[1,2,3],[4,5,6],[7,8,9]])
print(multiply(mymatrix,myones))
print(mymatrix*myones)
print(power(mymatrix,2))
print(mymatrix.transpose())

#linalg
print("det:", linalg.det(myeye))
print("inv:", linalg.inv(myeye))
print("rank:", linalg.matrix_rank(myeye))

网友评论

登录后评论
0/500
评论
止于至玄
+ 关注