In [1]:
import numpy as np
import matplotlib.pyplot as plt

Outer product: 外積

$\left[ \begin{matrix} 1 \\ 0 \\ 2 \\ 5 \\ 6 \end{matrix} \right] [a \: b \: c \: d]=\left[ \begin{matrix} 1a \: 1b \: 1c \: 1d \\ 0a \: 0b \: 0c \: 0d \\ 2a \: 2b \: 2c \: 2d \\ 5a \: 5b \: 5c \: 5d \\ 6a \: 6b \: 6c \: 6d \end{matrix} \right]$

In [2]:
v1 = np.random.randn(50)
v2 = np.random.randn(80)

# np.dot(v1,v2) # invalid
op = np.outer(v1,v2) # valid
print(op)
plt.imshow(op)
plt.show()
[[ 1.20327953  1.29020789 -1.95318317 ... -2.0630929   3.46189655
  -4.57252225]
 [ 0.44154739  0.47344604 -0.71672701 ... -0.75705874  1.27035436
  -1.67790212]
 [-0.0197952  -0.02122527  0.0321319  ...  0.03394003 -0.05695181
   0.07522276]
 ...
 [-0.44253366 -0.47450356  0.71832793 ...  0.75874975 -1.27319189
   1.68164998]
 [ 0.47063559  0.50463566 -0.76394345 ... -0.80693216  1.35404259
  -1.78843873]
 [-0.49800093 -0.53397794  0.80836331 ...  0.85385162 -1.43277405
   1.89242837]]

Commutative

$\quad a \times b = b \times a$

NOT Matrix commutative

$\quad np.outer(v,w) \ne np.outer(w,v)$

In [3]:
v = np.arange(1,11)
w = np.arange(1,6)

print(np.outer(v,w))
print('')
print(np.outer(w,v))
[[ 1  2  3  4  5]
 [ 2  4  6  8 10]
 [ 3  6  9 12 15]
 [ 4  8 12 16 20]
 [ 5 10 15 20 25]
 [ 6 12 18 24 30]
 [ 7 14 21 28 35]
 [ 8 16 24 32 40]
 [ 9 18 27 36 45]
 [10 20 30 40 50]]

[[ 1  2  3  4  5  6  7  8  9 10]
 [ 2  4  6  8 10 12 14 16 18 20]
 [ 3  6  9 12 15 18 21 24 27 30]
 [ 4  8 12 16 20 24 28 32 36 40]
 [ 5 10 15 20 25 30 35 40 45 50]]

Scalar-multiplication-commutative

$\quad c\text{vw}^T = \text v c \text w^T = \text{vw}^Tc$

v,w: vector, c: scalar

In [4]:
s = 4

res1 = s*np.outer(v,w)
res2 = np.outer(s*v,w)
res3 = np.outer(v,s*w)
res4 = np.outer(v,w)*s

print(res1-res2)
print(res1-res3)
print(res1-res4)
[[0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]
[[0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]
[[0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]