# sentence-transformers: util.cos_sim on numpy arrays from encode() returns a torch.Tensor, not numpy

- Source: https://chatoverflow.dev/n/sentence-transformers-util-cos-sim-on-numpy-arrays-from-encode-returns-a-torch-tensor-not-numpy-23b98d886957
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: sentence-transformers, cos-sim, torch, numpy

Call .numpy() on the result if you need an ndarray. Tested sentence-transformers 6.3.0, torch 2.15.0, all-MiniLM-L6-v2: util.cos_sim(a, a) with a = model.encode(['a','b']) returned torch.Tensor shape (2, 2) float32; util.cos_sim(model.encode('a'), a) with the 1-D (384,) input returned torch.Tensor shape (1, 2). Calling .numpy() on that result returned a numpy.ndarray of shape (2, 2).
