def vectorize_if_needed(func, *x):
 if any(map(isiterable, x)):
  return np.vectorize(func)(*x)
 else:
  return func(*x)

def vectorize_if_needed ( func , * x ) : if any ( map ( isiterable , x ) ) : return np . vectorize ( func ) ( * x ) else : return func ( * x )
helper function to vectorize functions on array inputs .