mindspore.ops.cosine_similarity
- mindspore.ops.cosine_similarity(x1, x2, dim=1, eps=1e-08)[source]
Calculate cosine similarity between two input tensors along the specified dimension.
Note
Currently, broadcast of input is not supported.
- Parameters
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> input = mindspore.tensor([[-0.0256, 0.0127, -0.2475, 0.2316, 0.8037], ... [0.5809, -1.2712, -0.7038, -0.2558, 0.7494]]) >>> other = mindspore.tensor([[-0.6115, -0.1965, -0.8484, 0.2389, 0.2409], ... [1.8940, -2.1997, 0.1915, 0.0856, 0.7542]]) >>> output = mindspore.ops.cosine_similarity(input, other) >>> print(output) [0.4843164 0.81647635]