Manipulating curves with python
Question: So I am using this python script to create the curves you see in the image.
Without going into detail about the real usage of this, my question is:

-Is there a way to create the blue and yellow curves without the linear values (red curve) ? Based on the blue line "formula" ( **sin(x*90*pi/180)** )

-Also, do I really need to create a for loop and append values like I do in the script or is there a more "clean" way of creating the array of values in one line?

In the end I just want to make sure that with my limited knowledge of maths
and python I am not making it more complex than it's needed. Thank you.

![curves](http://i.stack.imgur.com/Bu85y.jpg)

    
    
    ### RED CURVE ###
    
    linearValues = []
    
    for i in range(0,91):
        linearValues.append( float(  float(i)/float(90) ) )
    
    linearValues.reverse()
    
    
    
    ### BLUE CURVE ###
    
    blueCurveValues = []
    
    for i in range(0,91):
        blueCurveValues.append( math.sin(linearValues[i]*90*math.pi/180) )
    
    
    
    ### YELLOW CURVE ###
    
    yellowCurveValues = []
    
    for i in range(0,91):
        yellowCurveValues.append( float( linearValues[i]-(blueCurveValues[i]-linearValues[i]) ) )    
    


Answer: In Python 2, you should cast `int`s to `float`s before dividing (if you don’t
want integer division). And then you only need the cast when you’re dividing
two `int`s, which only happens for `linearValues` (and you’d only need
`float(i)/90` or `i/float(90)`, not three casts). But in Python 3 (or using
`from __future__ import division`), this is done automatically, and you don’t
need any calls to `float`. I’ve removed them.

The Pythonic way for creating your lists is called “list comprehension”.
Translating exactly what you’ve written, this would be:

    
    
    linearValues = [ i/90 for i in range(90,-1,-1) ]
    blueCurveValues = [ math.sin(linearValues[i]*90*math.pi/180) for i in range(91) ]
    yellowCurveValues = [ linearValues[i]-(blueCurvevalues[i]-linearValues[i] for i in range(91) ]
    

If you want to not have the linearValues calculated, the obvious thing to do
is simply replace `linearValues[i]` with `i/90` every time. This would
simplify your blue values formula, but only marginally so your yellow. At the
least, you may want to consider changing `90*math.pi/180` to `math.pi/2` (or
`(i/90*90*math.pi/180)` to `(i*math.pi/180)`). But this is still using the red
curve, just under the hood.

Another option for creating your lists would be `map`:

    
    
    linearValues = map(lambda x:x/90,range(90,-1,-1))
    blueCurveValues = map(lambda x:math.sin(x*90*math.pi/180),linearValues)
    yellowCurveValues = map(lambda x,y:x-(y-x),linearValues,blueCurveValues)
    

`map` and `lambda` is generally harder to read than a list comprehension, but
a shorter formula is generally easier. So red should probably be a list
comprehension. Blue and yellow would depend on your preference.

