simplecosine
raw JSON → 1.2 verified Fri May 01 auth: no python
Simple cosine distance calculation for vectors. Version 1.2 provides a straightforward function to compute cosine similarity or distance between two vectors. No active development, stable API.
pip install simplecosine Common errors
error ModuleNotFoundError: No module named 'simplecosine' ↓
cause Package not installed
fix
Run 'pip install simplecosine'
error ImportError: cannot import name 'cosine_distance' from 'simplecosine' ↓
cause Wrong import path (top-level instead of submodule)
fix
Use 'from simplecosine.cosine import cosine_distance'
Warnings
gotcha cosine_distance returns cosine distance (1 - similarity), not similarity. Many users expect similarity and misinterpret the result. ↓
fix Use 1 - cosine_distance(a, b) to get cosine similarity
gotcha The function only works with 2D vectors; does not support sparse arrays or arrays of different lengths. It will raise error or give wrong results. ↓
fix Ensure both vectors are Python lists of floats/ints of same length
Imports
- cosine_distance wrong
from simplecosine import cosine_distancecorrectfrom simplecosine.cosine import cosine_distance
Quickstart
import os
from simplecosine.cosine import cosine_distance
v1 = [1, 0, 0]
v2 = [0, 1, 0]
result = cosine_distance(v1, v2)
print(result) # Output: 1.0