Divide elements of a list by a number

-1

Hello

I'm an astrophysicist and I need to know how to "normalize" an astropy function:

blackbody_lambda(wavelenght, temperatureG)

For this specific value:

1279894.374188775erg / (Angstrom cm2 s sr) .

I use python.

Hugs!

    
asked by anonymous 22.01.2018 / 16:45

1 answer

1

Division

You can do:

myList = [1,2,3,4,5,6,7,8,9]
myInt = 10
newList = [float(i) / myInt for i in myList]

Or if you need to keep the reference in the original list

myList[:] = [float(i) / myInt for i in myList]

You can also use the NumPy

import numpy as np
myArray = np.array([1,2,3,4,5,6,7,8,9])
myInt = 10
newArray = myArray/myInt

Normalization

Now if you want to normalize against the unit using the sum:

mySum = sum(myArray)
norm = [float(i)/mySum for i in myArray]

or by using the maximum:

myMax = max(myArray)
norm = [float(i)/myMax for i in myArray]
    
22.01.2018 / 18:54