Created
October 25, 2011 13:11
-
-
Save laat/1312674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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