Reputation: 89
I already know, and understand how I can normalize an array in Python, but I am trying to create a random array. I want the dot product of the array (when I dot it with itself) to equal a value of one. I have been looking for a way to do this for over twelve hours now, and can not find a way. Any help or ideas would be great. Thank you.
Upvotes: 2
Views: 4571
Reputation: 19634
This will do the job:
import numpy as np
x=np.random.randn(5)
x=x/np.linalg.norm(x)
Then np.dot(x,x)
is 1.0
Upvotes: 3