How do you normalize a M*N vector, such that the sum of all its elements is now equal to 1. I browsed online a little, and nothing seems to quite match what I need. Thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You add up all the elements, then divide each element by the sum.
Obviously, the division (at least) needs to be in floating point. Since that indicates a floating point matrix, doing the summing while maintaining maximum accuracy will be non-trivial.
Just for example, if you have one large element, and a lot of small elements, you’ll probably get a more accurate result from adding all the small elements together, then adding that sum to the large element, than if you added each small element to the large one individually.
Edit: I suppose I should add that the usual way to deal with this is called Kahan summation, after the high guru of numerical analysis, William Kahan.