I have a 40*4 matrixM and a vectorA with 40 elements. I want to calculate the cosine distance between A and each column vector in M.
Do I really need to write like this?
print [cosine(M[:,i],A) for i in range(A.shape[1])]
Or there’s another better way to do this?
The document of cosine can be viewed here: http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cosine.html#scipy.spatial.distance.cosine
Thanks!
Perhaps a more functional way would be to use
functools.partialto bind the second argument ofcosinetoAand then usemapto apply this bound function to the columns ofM