回答編集履歴
2
修正
test
CHANGED
@@ -27,6 +27,12 @@
|
|
27
27
|
# (6, 1) x (1, 6)
|
28
28
|
|
29
29
|
c = a.reshape(-1, 1) @ b.reshape(1, -1)
|
30
|
+
|
31
|
+
# c = a[:, np.newaxis] @ b[np.newaxis] でも同じ
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
30
36
|
|
31
37
|
print(c)
|
32
38
|
|
1
修正
test
CHANGED
@@ -43,3 +43,73 @@
|
|
43
43
|
# [ 600 1200 1800]]
|
44
44
|
|
45
45
|
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
## `a.reshape(-1, 1) * b.reshape(1, -1)` で同じ結果が計算できた理由
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
```python
|
54
|
+
|
55
|
+
[[1]
|
56
|
+
|
57
|
+
[2]
|
58
|
+
|
59
|
+
[3]
|
60
|
+
|
61
|
+
[4]
|
62
|
+
|
63
|
+
[5]
|
64
|
+
|
65
|
+
[6]]
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
と
|
70
|
+
|
71
|
+
```python
|
72
|
+
|
73
|
+
[[100 200 300]]
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
を演算しようとしたときにブロードキャストされて、
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```python
|
82
|
+
|
83
|
+
[[1, 1, 1],
|
84
|
+
|
85
|
+
[2, 2, 2],
|
86
|
+
|
87
|
+
[3, 3, 3],
|
88
|
+
|
89
|
+
[4, 4, 4],
|
90
|
+
|
91
|
+
[5, 5, 5],
|
92
|
+
|
93
|
+
[6, 6, 6]]
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
と
|
98
|
+
|
99
|
+
```python
|
100
|
+
|
101
|
+
array([[100, 200, 300],
|
102
|
+
|
103
|
+
[100, 200, 300],
|
104
|
+
|
105
|
+
[100, 200, 300],
|
106
|
+
|
107
|
+
[100, 200, 300],
|
108
|
+
|
109
|
+
[100, 200, 300],
|
110
|
+
|
111
|
+
[100, 200, 300]])
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
の要素同士の積になって、たまたま行列積と同じ結果になりました。
|