Is there a built-in method for normalising an n-vector ( i.e. evaluating the unit vector v_{hat} = v/||v|| for an n-dimensional vector) in Python or in either of the major Python numerical libraries numpy or scipy?
I've written a method using norm from the numpy linear algebra module (numpy.linalg):
def normaliseVector(nVector):
return nVector/numpy.linalg.norm(nVector)
which seems to work fine. I tested it with the following input:
normaliseVector([3, 4, 5])
which returns the correct answer for this case. It just struck me that there might be a method out there for doing this already, or if not that it might be a useful thing to have a well-tested method for this.