about // doc

# Quick Reference of NumPy and SciPy

## General info

## Linear regression

## Find indices of an array

## Find the size of a matrix

## NumPy for Matlab Users

## Read Text Tables in Python

*Last modified: Jun, 2014*

- NumPy functions on sorting, searching and counting

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.

- Most commonly, function numpy.where is the closest one to the “find” in Matlab:

will return a tuple “(array([1, 2]),)” which is the array of matched indices.

- Or, a custom function mimicking the find in Matlab should great.

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/