当前位置:网站首页>Numpy04_ Linear algebra (unfinished)
Numpy04_ Linear algebra (unfinished)
2022-07-22 02:21:00 【phac123】
linear algebra
introduction
Numpy Defined matrix type , Use this matrix Type creates a matrix object , Their addition, subtraction, multiplication and division operations are calculated in matrix mode by default , So the usage and Matlab Very similar . But because of NumPy At the same time ndarray and matrix object , Therefore, users can easily confuse the two . This is against it. Python Of " Explicit is better than implicit ", Therefore, the use of matrix, ad locum , We still use ndarray To introduce .
Matrix and vector product
numpy.dot(a, b[, out]) Calculate the product of two matrices , If it is a one-dimensional array, it is their inner product .
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 3, 4, 5, 6])
z = np.dot(x, y) #x1*y1 + x2*y2 +...+ xn*yn
print(z) # 70
x = np.array([[1, 2, 3], [3, 4, 5], [6, 7, 8]])
print(x)
# [[1 2 3]
# [3 4 5]
# [6 7 8]]
y = np.array([[5, 4, 2], [1, 7, 9], [0, 4, 5]])
print(y)
# [[5 4 2]
# [1 7 9]
# [0 4 5]]
z = np.dot(x, y) # matrix multiplication
print(z)
# [[ 7 30 35]
# [ 19 60 67]
# [ 37 105 115]]
z = np.dot(y, x)
print(z)
# [[ 29 40 51]
# [ 76 93 110]
# [ 42 51 60]]
边栏推荐
猜你喜欢
Seata details of distributed transactions
[academic related] recommended by Chen Tianqi, Wang William and others: a little advice from the winner of ACL best paper award to new researchers
Skywalking server building and microservice access to skywalking
【开发教程6】AI语音人脸识别(会议记录仪/人脸打卡机)-串口
SQL基本语句练习
【学术相关】陈天奇、王威廉等人推荐:ACL最佳论文奖得主给新入行研究者的一点建议...
Creation of gateway routing service
weirdo A company's interview questions asked about toilet habits, eating time, sleeping time, etc
Tencent techo hub landed in Fuzhou 723 for the first time in 2022 to discuss industrial digitalization with developers!
Childhood memories games are coming - greedy snakes, come and write your own games
随机推荐
Creation of configuration files in Nacos configuration center and reading of Nacos configuration center by microservices
Filtration concept (feasibility analysis)
3537. Tree lookup
Chapter 3 business function development (to display the main page of clues and query the data of each drop-down box of the form)
架构模式 节选自《闻缺陷则喜》(此书可免费下载)
OSPF comprehensive experiment
Feign details, log configuration + contract settings + timeout + custom interceptors
Objet js: détection de l'existence d'attributs
mysql进阶(十四) 批量更新与批量更新多条记录的不同值实现方法
3537. 树查找
R语言ggplot2可视化:ggplot2可视化分组箱图,将可视化图像的图例(legend)放置在图像底部居中、其中图例信息水平平铺 (position legend bottom center)
(闲暇)LeetCode9. Palindrome Number
解决报错 OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized
学习STM32,从HAL库的框架设计开始
分布式事务之二阶段提交、AT模式、TCC模式
OSPF综合实验
【214】PHP读取目录下所有文件的写法
QT hodgepodge (total)
The sum of the last three numbers
左耳朵耗子:云原生时代的开发者应具备的5大能力