def makeMappingArray(N, data):
try:<EOL><INDENT>adata = np.array(data)<EOL><DEDENT>except:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>shape = adata.shape<EOL>if len(shape) != <NUM_LIT:2> and shape[<NUM_LIT:1>] != <NUM_LIT:3>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>x  = adata[:,<NUM_LIT:0>]<EOL>y0 = adata[:,<NUM_LIT:1>]<EOL>y1 = adata[:,<NUM_LIT:2>]<EOL>if x[<NUM_LIT:0>] != <NUM_LIT:0.> or x[-<NUM_LIT:1>] != <NUM_LIT:1.0>:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>if np.sometrue(np.sort(x)-x):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>x = x * (N-<NUM_LIT:1>)<EOL>lut = np.zeros((N,), np.float)<EOL>xind = np.arange(float(N))<EOL>ind = np.searchsorted(x, xind)[<NUM_LIT:1>:-<NUM_LIT:1>]<EOL>lut[<NUM_LIT:1>:-<NUM_LIT:1>] = ( ((xind[<NUM_LIT:1>:-<NUM_LIT:1>] - x[ind-<NUM_LIT:1>]) / (x[ind] - x[ind-<NUM_LIT:1>]))<EOL>* (y0[ind] - y1[ind-<NUM_LIT:1>]) + y1[ind-<NUM_LIT:1>])<EOL>lut[<NUM_LIT:0>] = y1[<NUM_LIT:0>]<EOL>lut[-<NUM_LIT:1>] = y0[-<NUM_LIT:1>]<EOL>np.clip(lut, <NUM_LIT:0.0>, <NUM_LIT:1.0>)<EOL>return lut<EOL>
Create an *N* -element 1-d lookup table

    *data* represented by a list of x,y0,y1 mapping correspondences.
    Each element in this list represents how a value between 0 and 1
    (inclusive) represented by x is mapped to a corresponding value
    between 0 and 1 (inclusive). The two values of y are to allow
    for discontinuous mapping functions (say as might be found in a
    sawtooth) where y0 represents the value of y for values of x
    <= to that given, and y1 is the value to be used for x > than
    that given). The list must start with x=0, end with x=1, and
    all values of x must be in increasing order. Values between
    the given mapping points are determined by simple linear interpolation.

    The function returns an array "result" where ``result[x*(N-1)]``
    gives the closest value for values of x between 0 and 1.