The inner product of vectors or the multiplication of the matrix of 1 row x column and x row 1 column is a value, but if you use it as an array, it should be in the form of an array [[]] or [].
import numpy as np
t1 = np.zeros(shape = (3,1))
y2 = np.arange(3).reshape(3,1)
print(t1)
print(y2)
print(t1-y2)
print((t1-y2).T)
print((t1-y2).T.dot(t1-y2))
Execution result
[[ 0.]
[ 0.]
[ 0.]]
y2
[[0]
[1]
[2]]
t1-y2
[[ 0.]
[-1.]
[-2.]]
(t1-y2).T
[[ 0. -1. -2.]]
(t1-y2).T.dot(t1-y2)
[[ 5.]]```
I want to get the value from here, but it seems that .flatten () is not enough
#### **`print((t1-y2).T.dot(t1-y2).flatten())`**
[ 5.]
Therefore, I will specify that it is the 0th element.
#### **`print((t1-y2).T.dot(t1-y2).flatten()[0])`**
->5.0```
Solved safely
Recommended Posts