def argmaxrnd(a, random_seed=None):
 if (a.ndim > 2):
  raise ValueError('argmaxrnd only accepts arrays of up to 2 dim')
 def rndc(x):
  return random.choice((x == bn.nanmax(x)).nonzero()[0])
 random = (np.random if (random_seed is None) else np.random.RandomState(random_seed))
 return (rndc(a) if (a.ndim == 1) else np.apply_along_axis(rndc, axis=1, arr=a))

def argmaxrnd ( a , random_seed = None ) : if ( a . ndim > 2 ) : raise ValueError ( 'argmaxrnd only accepts arrays of up to 2 dim' ) def rndc ( x ) : return random . choice ( ( x == bn . nanmax ( x ) ) . nonzero ( ) [ 0 ] ) random = ( np . random if ( random_seed is None ) else np . random . RandomState ( random_seed ) ) return ( rndc ( a ) if ( a . ndim == 1 ) else np . apply_along_axis ( rndc , axis = 1 , arr = a ) )
find the index of the maximum value for a given 1-d numpy array .