python 中的数组乘法
multiplication of arrays in python
这是 python 中出现问题的代码行。我正在处理图像,但没有分类数据。
normalized_face_vector = [88, 90000]
eigen_vectors = [88, 88]
low_dimension_to_high_dimension = normalized_face_vector.dot(eigen_vectors)
当上面的行执行时出现以下错误。
shapes (88,90000) and (88,88) not aligned: 90000 (dim 1) != 88 (dim 0)
如何执行 normalized_face_vector 与 eigen_vectors 的乘法运算?
您收到错误消息是因为您的两个矩阵的尺寸都不正确。
在您的错误消息中明确提到:shapes (88,90000) and (88,88) not aligned: 90000 (dim 1) != 88 (dim 0).
对于点积 Matrix_A 的列数必须等于 Matrix_B 的行数。
在您的情况下,您可以对 matrix_A 进行 转置 ,然后应用点积。
查看此示例,这可能对您有所帮助:
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
这是 python 中出现问题的代码行。我正在处理图像,但没有分类数据。
normalized_face_vector = [88, 90000]
eigen_vectors = [88, 88]
low_dimension_to_high_dimension = normalized_face_vector.dot(eigen_vectors)
当上面的行执行时出现以下错误。
shapes (88,90000) and (88,88) not aligned: 90000 (dim 1) != 88 (dim 0)
如何执行 normalized_face_vector 与 eigen_vectors 的乘法运算?
您收到错误消息是因为您的两个矩阵的尺寸都不正确。 在您的错误消息中明确提到:shapes (88,90000) and (88,88) not aligned: 90000 (dim 1) != 88 (dim 0).
对于点积 Matrix_A 的列数必须等于 Matrix_B 的行数。
在您的情况下,您可以对 matrix_A 进行 转置 ,然后应用点积。
查看此示例,这可能对您有所帮助:
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