Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
WestZY
MachineLearning
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
MachineLearning
/
src
/
python
/
1.MLFoundation
/
NumPy.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
56 lines (52 loc) · 1.72 KB
master
Breadcrumbs
MachineLearning
/
src
/
python
/
1.MLFoundation
/
NumPy.py
Copy path
Top
File metadata and controls
Code
Blame
56 lines (52 loc) · 1.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# coding:utf8
'''
Created on 2017-05-18
Update on 2017-05-18
@author: Peter Harrington/1988/片刻
《机器学习实战》更新地址:https://github.com/apachecn/MachineLearning
'''
from
numpy
import
random
,
mat
,
eye
'''
# NumPy 矩阵和数组的区别
NumPy存在2中不同的数据类型:
1. 矩阵 matrix
2. 数组 array
相似点:
都可以处理行列表示的数字元素
不同点:
1. 2个数据类型上执行相同的数据运算可能得到不同的结果。
2. NumPy函数库中的 matrix 与 MATLAB中 matrices 等价。
'''
# 生成一个 4*4 的随机数组
randArray
=
random
.
rand
(
4
,
4
)
# 转化关系, 数组转化为矩阵
randMat
=
mat
(
randArray
)
'''
.I 表示对矩阵求逆(可以利用矩阵的初等变换)
意义:逆矩阵是一个判断相似性的工具。逆矩阵A与列向量p相乘后,将得到列向量q,q的第i个分量表示p与A的第i个列向量的相似度。
参考案例链接:
https://www.zhihu.com/question/33258489
http://blog.csdn.net/vernice/article/details/48506027
.T 表示对矩阵转置(行列颠倒)
* 等同于: .transpose()
.A 返回矩阵基于的数组
参考案例链接:
http://blog.csdn.net/qq403977698/article/details/47254539
'''
invRandMat
=
randMat
.
I
TraRandMat
=
randMat
.
T
ArrRandMat
=
randMat
.
A
# 输出结果
print
'randArray='
,
randArray
print
'randMat='
,
randMat
print
'invRandMat='
,
invRandMat
print
'TraRandMat='
,
TraRandMat
print
'ArrRandMat='
,
ArrRandMat
# 矩阵和逆矩阵 进行求积 (单位矩阵,对角线都为1嘛,理论上4*4的矩阵其他的都为0)
myEye
=
randMat
*
invRandMat
# 误差
print
myEye
-
eye
(
4
)
'''
如果上面的代码运行没有问题,说明numpy安装没有问题
'''
You can’t perform that action at this time.