With np.matrix
, the *
operator does matrix multiplication rather than element-wise multiplication, which is what I assume you're trying to do.
You get a ValueError
because the two column vectors are not properly aligned for matrix multiplication. Their inner dimensions don't match, since their shapes are (N, 1)
and (N, 1)
respectively. They would need to be either (1, N)
, (N, 1)
(for the inner product) or (N, 1)
, (1, N)
(for the outer product) in order for matrix multiplication to work.
If you choose to stick to using np.matrix
to hold your data, you could use the np.multiply()
function to do element-wise multiplication:
result = np.multiply(new_train_data[:, 0], new_train_data[:, 1])
However, I would recommend that you use np.array
instead of np.matrix
in future. With np.array
the *
operator does element-wise multiplication, and the np.dot()
function (or the .dot()
method of the array) does matrix multiplication.