lundi 8 février 2016

method to circumvent if-else checking

I am just wondering if I want to implement a program that converts wavelength to (r,g,b) using the algorithm in this paper (p5-6): http://ift.tt/1nYAX11, instead of checking the value of wavelength using if-else like

if wavelength>380 and wavelength<410:
    # do something
elif wavelength<440:
    # do something
elif wavelength<490:
    # do something, and so on

Are there some genius method to avoid using if-else statement so that I can speed up the code? More specifically, suppose I store the wavelengths in a list or a numpy array, is it possible to have some sort of 'vectorized' method to generate the (r,g,b) values?

Aucun commentaire:

Enregistrer un commentaire