def distort_matrix_X(Z, X, f, new_xmin, new_xmax, subsample=<NUM_LIT:3>):
Z = _n.array(Z)<EOL>X = _n.array(X)<EOL>points = len(Z)*subsample<EOL>def zero_me(new_x): return f(new_x)-target_old_x<EOL>target_old_x = min(X)<EOL>new_xmin = find_zero_bisect(zero_me, new_xmin, new_xmax, _n.abs(new_xmax-new_xmin)*<NUM_LIT>)<EOL>target_old_x = max(X)<EOL>new_xmax = find_zero_bisect(zero_me, new_xmin, new_xmax, _n.abs(new_xmax-new_xmin)*<NUM_LIT>)<EOL>new_X = []<EOL>new_Z = []<EOL>bin_width = float(new_xmax-new_xmin)/(points)<EOL>for new_x in frange(new_xmin, new_xmax, bin_width):<EOL><INDENT>if f(new_x) <= max(X) and f(new_x) >= min(X):<EOL><INDENT>new_X.append(new_x)<EOL>new_Z.append( interpolate(X,Z,f(new_x)) )<EOL><DEDENT><DEDENT>return _n.array(new_Z), _n.array(new_X)<EOL>
Applies a distortion (remapping) to the matrix Z (and x-values X) using function f.
returns new_Z, new_X

f is an INVERSE function old_x(new_x)

Z is a matrix. X is an array where X[n] is the x-value associated with the array Z[n].

new_xmin, new_xmax is the possible range of the distorted x-variable for generating Z

points is how many elements the stretched Z should have. "auto" means use the same number of bins