Skip to content

Instantly share code, notes, and snippets.

@npinto
Created September 4, 2012 21:36
Show Gist options
  • Select an option

  • Save npinto/3626866 to your computer and use it in GitHub Desktop.

Select an option

Save npinto/3626866 to your computer and use it in GitHub Desktop.

Revisions

  1. npinto created this gist Sep 4, 2012.
    11 changes: 11 additions & 0 deletions labels_to_integers.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    In [12]: l = ['a', 'a', 'c', 'c', 'c', 'b']

    In [13]: u = np.unique(l)

    In [14]: u
    Out[14]:
    array(['a', 'b', 'c'],
    dtype='|S1')

    In [15]: np.searchsorted(u, l)
    Out[15]: array([0, 0, 2, 2, 2, 1])