Last modified: Jun, 2014
Both NumPy and SciPy have functions for simple linear regression (see post). It is more intuitive to do in SciPy as follows:
The meaning of each output is self-explanatory in the code above.
The “find” function in Matlab is very handy, but it doesn’t have a direct clone in NumPy.
will return a tuple “(array([1, 2]),)” which is the array of matched indices.
Related functions on sorting, searching and counting are here.
This is equivalent to the “size” function in Matlab:
where “mtx” is a matrix.
However, there is a caveat: if the matrix is an 1D array, then the returned tuple may miss the corresponding “1”. For example:
may just return (5,) instead of (5,1). This is the difference from the “size” function in Matlab.
http://wiki.scipy.org/NumPy_for_Matlab_Users
http://penandpants.com/2012/03/09/reading-text-tables-with-python/