def fast_replace(data, keys, values, skip_checks=False):
 assert np.allclose(keys.shape, values.shape)
 if (not skip_checks):
  msg = 'data has elements not in keys'
  assert (data.max() <= keys.max()), msg
 sdx = np.argsort(keys)
 (keys, values) = (keys[sdx], values[sdx])
 idx = np.digitize(data, keys, right=True)
 new_data = values[idx]
 return new_data

def fast_replace ( data , keys , values , skip_checks = False ) : assert np . allclose ( keys . shape , values . shape ) if ( not skip_checks ) : msg = 'data has elements not in keys' assert ( data . max ( ) <= keys . max ( ) ) , msg sdx = np . argsort ( keys ) ( keys , values ) = ( keys [ sdx ] , values [ sdx ] ) idx = np . digitize ( data , keys , right = True ) new_data = values [ idx ] return new_data
do a search-and-replace in array data .