def linregress(x, y=None):
TINY = <NUM_LIT><EOL>if y is None:  <EOL><INDENT>x = asarray(x)<EOL>if x.shape[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>x, y = x<EOL><DEDENT>elif x.shape[<NUM_LIT:1>] == <NUM_LIT:2>:<EOL><INDENT>x, y = x.T<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>" % str(x.shape)<EOL>raise ValueError(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>x = asarray(x)<EOL>y = asarray(y)<EOL><DEDENT>n = len(x)<EOL>xmean = np.mean(x,None)<EOL>ymean = np.mean(y,None)<EOL>ssxm, ssxym, ssyxm, ssym = np.cov(x, y, bias=<NUM_LIT:1>).flat<EOL>r_num = ssxym<EOL>r_den = np.sqrt(ssxm*ssym)<EOL>if r_den == <NUM_LIT:0.0>:<EOL><INDENT>r = <NUM_LIT:0.0><EOL><DEDENT>else:<EOL><INDENT>r = r_num / r_den<EOL>if (r > <NUM_LIT:1.0>):<EOL><INDENT>r = <NUM_LIT:1.0><EOL><DEDENT>elif (r < -<NUM_LIT:1.0>):<EOL><INDENT>r = -<NUM_LIT:1.0><EOL><DEDENT><DEDENT>df = n-<NUM_LIT:2><EOL>t = r*np.sqrt(df/((<NUM_LIT:1.0>-r+TINY)*(<NUM_LIT:1.0>+r+TINY)))<EOL>prob = distributions.t.sf(np.abs(t),df)*<NUM_LIT:2><EOL>slope = r_num / ssxm<EOL>intercept = ymean - slope*xmean<EOL>sterrest = np.sqrt((<NUM_LIT:1>-r*r)*ssym / ssxm / df)<EOL>return slope, intercept, r, prob, sterrest<EOL>
Calculate a regression line

This computes a least-squares regression for two sets of measurements.

Parameters
----------
x, y : array_like
    two sets of measurements.  Both arrays should have the same length.
    If only x is given (and y=None), then it must be a two-dimensional
    array where one dimension has length 2.  The two sets of measurements
    are then found by splitting the array along the length-2 dimension.

Returns
-------
slope : float
    slope of the regression line
intercept : float
    intercept of the regression line
r-value : float
    correlation coefficient
p-value : float
    two-sided p-value for a hypothesis test whose null hypothesis is
    that the slope is zero.
stderr : float
    Standard error of the estimate


Examples
--------
>>> from scipy import stats
>>> import numpy as np
>>> x = np.random.random(10)
>>> y = np.random.random(10)
>>> slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)

# To get coefficient of determination (r_squared)

>>> print "r-squared:", r_value**2
r-squared: 0.15286643777