def perm(N, k, exact=False):
 if exact:
  if ((k > N) or (N < 0) or (k < 0)):
   return 0
  val = 1
  for i in xrange(((N - k) + 1), (N + 1)):
   val *= i
  return val
 else:
  (k, N) = (asarray(k), asarray(N))
  cond = (((k <= N) & (N >= 0)) & (k >= 0))
  vals = poch(((N - k) + 1), k)
  if isinstance(vals, np.ndarray):
   vals[(~ cond)] = 0
  elif (not cond):
   vals = np.float64(0)
  return vals

def perm ( N , k , exact = False ) : if exact : if ( ( k > N ) or ( N < 0 ) or ( k < 0 ) ) : return 0 val = 1 for i in xrange ( ( ( N - k ) + 1 ) , ( N + 1 ) ) : val *= i return val else : ( k , N ) = ( asarray ( k ) , asarray ( N ) ) cond = ( ( ( k <= N ) & ( N >= 0 ) ) & ( k >= 0 ) ) vals = poch ( ( ( N - k ) + 1 ) , k ) if isinstance ( vals , np . ndarray ) : vals [ ( ~ cond ) ] = 0 elif ( not cond ) : vals = np . float64 ( 0 ) return vals
permutations of n things taken k at a time .