Skip to content

Instantly share code, notes, and snippets.

@aplz
Last active November 26, 2020 08:21
Show Gist options
  • Save aplz/cbaf270431286fd9fadb1060bb440c0d to your computer and use it in GitHub Desktop.
Save aplz/cbaf270431286fd9fadb1060bb440c0d to your computer and use it in GitHub Desktop.
Create a sparse vector for dlib from a numpy array
"""How to create a sparse vector for dlib from a numpy array.
dlib: http://dlib.net/
"""
import dlib
import numpy
vector = [0,2,0]
sv = dlib.sparse_vector()
for i in numpy.nonzero(vector)[0]:
sv.append(dlib.pair(i, vector[i]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment