使用python学线性代数
Prerequisites:
先决条件:
Property 1:
属性1:
Outer product in linear algebra involves two vectors of any dimension but the order is important. When the order is reversed, the product changes, and the resultant matrix changes.
线性代数的外积涉及两个任意维度的向量,但是顺序很重要。 当顺序颠倒时,乘积将更改,结果矩阵也会更改。
Syntax:
句法:
numpy.outer(Vec_1, Vec_2) != numpy.outer(Vec_2, Vec_1)
Program:
程序:
# Linear Algebra Learning Sequence
# Outer Product Property I
import numpy as np
a = np.array([2, 4, 8, 7, 7])
b = np.array([2, 3, 1, 7, 8])
#outer product in both order
opab = np.outer(a,b)
opba = np.outer(b,a)
print('---A---\n', a)
print('\n\n---B---\n', b)
print('\n\nOuter Product as A.B : ', opab)
print('\n\nOuter Product as A.B : ', opba)
Output:
输出:
---A---
[2 4 8 7 7]
---B---
[2 3 1 7 8]
Outer Product as A.B : [[ 4 6 2 14 16]
[ 8 12 4 28 32]
[16 24 8 56 64]
[14 21 7 49 56]
[14 21 7 49 56]]
Outer Product as A.B : [[ 4 8 16 14 14]
[ 6 12 24 21 21]
[ 2 4 8 7 7]
[14 28 56 49 49]
[16 32 64 56 56]]
Property 2:
属性2:
Outer product in linear algebra involves two vectors of any dimension but the order is important. If the first Vector is of M dimension and 2nd of N, then the outer product matrix will have dimension MxN.
线性代数的外积涉及两个任意维度的向量,但是顺序很重要。 如果第一个向量的维数为M ,第二个向量的维数为N ,则外部乘积矩阵的维数为MxN 。
Syntax:
句法:
[m,n] = numpy.shape(numpy.outer(Vec_1, Vec_2))
Program:
程序:
# Linear Algebra Learning Sequence
# Outer Product Property I
import numpy as np
a = np.array([2, 4, 8, 7, 7, 9, -6])
b = np.array([2, 3, 1, 7, 8])
#outer product in both order
opab = np.outer(a,b)
dim = np.shape(opab)
print('A : ', a, '\nDimension of first vector :', len(a))
print('B : ', b, '\nDimension of second vector : ', len(b))
print('\n\nOuter Product as A.B : ', opab)
print('Outer product Dimensions : ', dim)
Output:
输出:
A : [ 2 4 8 7 7 9 -6]
Dimension of first vector : 7
B : [2 3 1 7 8]
Dimension of second vector : 5
Outer Product as A.B : [[ 4 6 2 14 16]
[ 8 12 4 28 32]
[ 16 24 8 56 64]
[ 14 21 7 49 56]
[ 14 21 7 49 56]
[ 18 27 9 63 72]
[-12 -18 -6 -42 -48]]
Outer product Dimensions : (7, 5)
翻译自: https://www.includehelp.com/python/outer-product-properties.aspx
使用python学线性代数