similarity()¶
- audmath.similarity(u, v)[source]¶
Cosine similarity between two arrays.
If the incoming arrays are of size , a single similarity value is returned. If one of the incoming arrays is of size , an array of size with similarities is returned. If the arrays are of size and an array of size with similarities is returned.
The input arrays can also be provided as
pandas.DataFrame
orpandas.Series
.The cosine similarity is given by .
- Parameters
- Return type
- Returns
similarity between arrays
Example
>>> similarity([1, 0], [1, 0]) np.float64(1.0) >>> similarity([1, 0], [0, 1]) np.float64(0.0) >>> similarity([1, 0], [-1, 0]) np.float64(-1.0) >>> similarity([[1, 0]], [1, 0]) array([1.]) >>> similarity([1, 0], [[1, 0], [0, 1]]) array([1., 0.]) >>> similarity([[1, 0], [0, 1]], [[1, 0]]) array([[1.], [0.]]) >>> similarity([[1, 0], [0, 1]], [[1, 0], [0, 1], [-1, 0]]) array([[ 1., 0., -1.], [ 0., 1., 0.]])