float(multiply(colvec1,colvec2).t * (matrix*matrix[i,:].t)) + c i new python , numpy , trying understand code snippet above does.
the multiply().t part performs element-by-element multiplication , transpose, , result becomes row vector.
i trying understand matrix[i,:] does. create sub-matrix picking i'th row vector or create sub-matrix i'th row vector way end of matrix?
the * performs dot-product converted float using float().
yes, matrix[i, :] give i:th row of matrix since : means "pick in dimension".
and no, a * b not dot product between a , b, element-wise product of a , b. dot product use of
a.dot(b) np.dot(a, b) @ b # python 3.5+ the above true long use np.ndarray class, did if created matrices/arrays using np.array, np.eye, np.zeros, etc. there np.matrix class multiplication operator * dot product, adviced never use since tends create confusion when mixed normal array type.
so going on in expression?
lets's break down parts.
multiply(colvec1,colvec2).t create transpose of element-wise product of colvec1 , colvec2.
matrix*matrix[i,:].t element-wise product between matrix , transpose of i:th row of matrix. due numpys broadcasting rules same multiplying (elementwise) each row of matrix i:th row.
what can see both these expressions create matrix/array , not scalar. therefore call float() fail, expects 1-element array or scalar.
my verdict has either been using np.matrix class, or has interpreted use of * wrong.
Comments
Post a Comment