I'm currently learning probability from an online course.
It's teaching me to use this amazingly simple method, and so far it has worked flawlessly!
Where e
is an element in the list of numbers to be normalized:
Calculate a normalizer (multiplier) like so:
normalizer = 1 / (e1 + e2 + e3)
Next, multiply the normalizer to every element in the list:
((e1 * normalizer) + (e2 * normalizer) + .... + (en * normalizer) ) == 1.0
... and they will add up to 1.0.
So taking your example of numbers 10 and 40:
normalizer = 1 / (10 + 40) = 0.02
(10 * 0.02) = 0.2
(40 * 0.02) = 0.8
(0.2 + 0.8) = 1.0
Hence we get our 1.0.
I've gone ahead and written a simple Python script that you can run on almost any Python interpreter and play around with the parameters and test the results.
# python script
import random as rnd
# number of items in list, change this to as huge a list as you want
itemsInList = 5
# specify min and max value bounds for randomly generated values
# change these to play around with different value ranges
minVal = 8
maxVal = 20
# creates a list of random values between minVal and maxVal, and sort them
numList = sorted( [rnd.randint(minVal, maxVal) for x in range(itemsInList)] )
print ('initial list is\n{}\n'.format(numList))
# calculate the normalizer, using: (1 / (sum_of_all_items_in_list))
normalizer = 1 / float( sum(numList) )
# multiply each item by the normalizer
numListNormalized = [x * normalizer for x in numList]
print('Normalized list is\n{}\n'.format(numListNormalized))
print('Sum of all items in numListNormalized is {}'.format(sum(numListNormalized)))
Running the code gives this sample output:
initial list is
[9, 12, 15, 16, 19]
Normalized list is
[0.1267605633802817, 0.16901408450704225, 0.2112676056338028, 0.22535211267605634, 0.26760563380281693]
Sum of all items in numListNormalized is 1.0
I hope this helps!