numpy.dot(vector_a, vector_b, out = None)
返回向量a和b的点积。它可以处理2D数组,但将其视为矩阵,并将执行矩阵乘法。对于N维,它是a的最后一个轴与b的second-to-last的总和:
dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
参数-
- vector_a : [数组]如果a是复数,则将其复共轭用于点积的计算。
- vector_b : [数组]如果b是复数,则将其复共轭用于点积的计算。
- out : [array,optional]输出参数必须是C-contiguous,并且其dtype必须是为dot(a,b)返回的dtype。
返回-
向量a和b的点积。如果vector_a和vector_b为一维,则返回标量
代码1-
# Python Program illustrating
# numpy.dot() method
import numpy as geek
# Scalars
product = geek.dot(5, 4)
print("Dot Product of scalar values : ", product)
# 1D array
vector_a = 2 + 3j
vector_b = 4 + 5j
product = geek.dot(vector_a, vector_b)
print("Dot Product : ", product)
输出-
Dot Product of scalar values : 20 Dot Product : (-7+22j)
Code1如何工作?
vector_a = 2 + 3j
vector_b = 4 + 5j
现在点产品
= 2(4 + 5j)+ 3j(4-5j)
= 8 + 10j + 12j-15
= -7 + 22j
代码2-
# Python Program illustrating
# numpy.dot() method
import numpy as geek
# 1D array
vector_a = geek.array([[1, 4], [5, 6]])
vector_b = geek.array([[2, 4], [5, 2]])
product = geek.dot(vector_a, vector_b)
print("Dot Product : \n", product)
product = geek.dot(vector_b, vector_a)
print("\nDot Product : \n", product)
"""
Code 2 : as normal matrix multiplication
"""
输出-
Dot Product : [[22 12] [40 32]] Dot Product : [[22 32] [15 32]]
相关用法
注:本文由纯净天空筛选整理自 numpy.dot() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。