Dividing list items by a number

Asked

Viewed 2,531 times

-1

Hello!

I am a student of astrophysics and 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 the python.

Hugs!

  • What would normalize the function in this case? What is the expected result?

1 answer

1

Splitting up

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 library 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 relative to the unit using the sum:

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

or using as much as possible:

myMax = max(myArray)
norm = [float(i)/myMax for i in myArray]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.