什么是两个行向量的外积

时间:2018-04-15 02:48:21

标签: python matrix

Wiki给出了列向量$ a $和$ b $的外积 $$ 一个= \ BEGIN {bmatrix} A_ {1} \\ a2} \\ a_ {3} \ {端} bmatrix, B = \ BEGIN {bmatrix} B_ {1} \\ b_ {2} \\ b_ {3} \ {端} bmatrix $$ $$ a⊗b= ab ^ {T} = \ begin {bmatrix} a_ {1} b_ {1} \ space \ space a_ {1} b_ {2} \ space \ space a_ {1} b_ {3} \\ a_ {2} b_ {1} \ space \ space a_ {2} b_ {2} \ space \ space a_ {2} b_ {3} \\ a_ {3} b_ {1} \ space \ space a_ {3} b_ {2} \ space \ space a_ {3} b_ {3} \ {端} bmatrix $$ 如果$ a $和$ b $是行向量, 根据{{​​3}},外部产品应该是这样的 $$ a = \ begin {bmatrix} a_ {1} \ space \ space a_ {2} \ space \ space a_ {3} \ end {bmatrix}, b = \ begin {bmatrix} b_ {1} \ space \ space b_ {2} \ space \ space b_ {3} \ end {bmatrix} $$ $$ a⊗b=a⊗_{K} b ^ {T} = \ begin {bmatrix} a_ {1} b_ {1} \ space \ space a_ {2} b_ {1} \ space \ space a_ {3} b_ {1} \\ a_ {1} b_ {2} \ space \ space a_ {2} b_ {2} \ space \ space a_ {3} b_ {2} \\ a_ {1} b_ {3} \ space \ space a_ {2} b_ {3} \ space \ space a_ {3} b_ {3} \ {端} bmatrix $$ 但是当我在python this中执行此操作时,它会给出相同的答案。

import numpy as np

a = np.array([[1], [2], [3]])
b = np.array([[4], [5], [6]])
col_result=np.outer(a, b)
row_result=np.outer(a.T, b.T)
print(col_result)
print(row_result)

答案是这样的:

[[ 4  5  6]
 [ 8 10 12]
 [12 15 18]]
[[ 4  5  6]
 [ 8 10 12]
 [12 15 18]]

那么,我写错了方程式还是python做错了?

1 个答案:

答案 0 :(得分:0)

这是numpy

的问题

然而,答案是:无论形状如何,numpy都会将输入变平为1D数组。您应该改为计算

 np.outer(b,a)