You may want to do:
```
S = cosine_similarity(X, Y)
S *= -1
S += 1
return S
```

Less readable but avoids a memory allocation. What do people think?