In [1]:
import numpy as np
In [28]:
w = np.array([1, 2, 3])
w_mat = np.expand_dims(w, axis=1) # col vec as mat
d = 3
T = 10
X = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
t = 0
np.dot(w.T, X[:, [t]])
Out[28]:
In [29]:
np.dot(w, X[:, t]) # all vector
Out[29]:
In [31]:
np.dot(w, X[:, [t]])
Out[31]:
maintain matrix
In [32]:
np.dot(w_mat.T, X[:, [t]])
Out[32]:
In [33]:
np.dot(w_mat.T, X)
Out[33]:
In [35]:
np.dot(w_mat, X)
Col vector by default
In [34]:
np.dot(w, X) # more tensor-feel
Out[34]:
In [39]:
X
Out[39]:
In [40]:
X.mean(axis=0) # np.mean(X, axis=0)
Out[40]:
In [41]:
X.sum(axis=0)
Out[41]:
In [42]:
X.dot(X)
Out[42]:
In [43]:
# However, element-wise must be np.xxx
np.divide(X, 2)
Out[43]:
In [44]:
np.divide(X, 2.0)
Out[44]: