pythonarraysnumpyvalueerror

Showing ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)


I am trying to use the following matrices and perform a dot product as shown in the code. I checked the size of the matrix and it is (1, 3) but it is throwing me error for the dot product.

import numpy as np 

b0 = np.matrix(np.random.rand(3))
n1 = np.cross(b0, b0)
print(np.shape(n1))

y = np.dot(n1, n1)

Solution

  • By converting the matrix to array by using

    n12 = np.squeeze(np.asarray(n2))
    
    X12 = np.squeeze(np.asarray(x1))
    

    solved the issue.