#NEWLINE# def _index_of( arr , lookup ) : #NEWLINE# #INDENT# 'Replace scalars in an array by their indices in a lookup table.\n\n    Implicitely assume that:\n\n    * All elements of arr and lookup are non-negative integers.\n    * All elements or arr belong to lookup.\n\n    This is not checked for performance reasons.\n\n    ' #NEWLINE# lookup = np . asarray ( lookup , dtype = np . int32 ) #NEWLINE# m = ( ( lookup . max ( ) if len ( lookup ) else 0 ) + 1 ) #NEWLINE# tmp = np . zeros ( ( m + 1 ) , dtype = np . int ) #NEWLINE# tmp [ ( - 1 ) ] = ( - 1 ) #NEWLINE# if len ( tmp ) : #NEWLINE# #INDENT# tmp [ lookup ] = np . arange ( len ( lookup ) ) #NEWLINE# #UNINDENT# return tmp [ arr ]