Search code examples
pythonimage-processingface-recognition

multiplication of arrays in python


Here is the line of code that makes the problem in python. I'm working with images and there is no categorical data.

normalized_face_vector = [88, 90000]
eigen_vectors = [88, 88]
low_dimension_to_high_dimension = normalized_face_vector.dot(eigen_vectors)

when the above line execute it gives below error.

shapes (88,90000) and (88,88) not aligned: 90000 (dim 1) != 88 (dim 0)

How can I perform multiplication of normalized_face_vector with eigen_vectors?


Solution

  • You are getting error because dimensions of your both matrix are not proper. In your error message it is clearly mentioned that : shapes (88,90000) and (88,88) not aligned: 90000 (dim 1) != 88 (dim 0) .

    For Dot product No. of columns of Matrix_A must be Equal to No. of Rows of Matrix_B.

    In your case you can take transpose of matrix_A and then apply dot product.

    Check out this example this may help you :

    import numpy as np
    Matrix_A=[               #4x5
        [3,4,6,4,6],
        [3,8,7,6,6],
        [2,7,9,2,2],
        [7,1,2,7,4]]
    Matrix_B=[               #4x4
        [8,4,9,5],
        [3,2,7,3],
        [9,7,2,6],
        [3,2,3,7]]
    Matrix_A=np.array(a)
    Matrix_B=np.array(b)
    Matrix_C=np.dot(Matrix_A.transpose(),Matrix_B)
    Matrix_C