Skip to content

Instantly share code, notes, and snippets.

@laat
Created October 25, 2011 13:11
Show Gist options
  • Save laat/1312674 to your computer and use it in GitHub Desktop.
Save laat/1312674 to your computer and use it in GitHub Desktop.
def normalize(vector):
""" returns a new normalized array """
vector = np.array(vector).reshape(2).reshape(2) # back to 1D array
s = sum(vector) # sum of the vector
return np.array([n / s for n in vector.flat]) # normalize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment