NumPy: matrix by vector multiplication

I have 1 matrix with the name A1(18,11) and 3 vectors with the name norms, offsetsand priorita(18,1).

When I try to perform this operation:

A1 =  (A1 + offsets) / norms * priorita

I get the following error:

A1 =  (A1 + offsets) / norms * priorita
  File "/usr/lib/python2.7/dist-packages/numpy/matrixlib/defmatrix.py", line 330, in __mul__
    return N.dot(self, asmatrix(other))
ValueError: matrices are not aligned

I can't figure it out because the matrices look the same to me. Could you help me understand this error?

+4
source share
2 answers

If you have matrix, no matter what it is matrix, and arrayor two matrixts. *always considered as matrix multiplication, therefore, an error not aligned, because it simply does not conduct a mesh operation. You will see that the trace goes __mul__()todefmatrix.pyc

, , np.multiply((A1 + offsets) / norms , priorita), , np.matrix(np.array((A1 + offsets) / norms )* np.array(priorita)), , , .

+2

.shape (A1 + offsets) / norms - (18, 11). (18, 11) (18, 1) ( / ). , , , , , , - -:

A1 =  ((A1 + offsets) / norms).T * priorita
+1

Source: https://habr.com/ru/post/1538218/


All Articles