Installing SciPy with pip

Prerequisite: sudo apt-get install build-essential gfortran libatlas-base-dev python-pip python-dev sudo pip install –upgrade pip Actual packages: sudo pip install numpy sudo pip install scipy Optional packages: sudo pip install matplotlib OR sudo apt-get install python-matplotlib sudo pip install -U scikit-learn sudo pip install pandas src

Computing the correlation coefficient between two multi-dimensional arrays

Correlation (default ‘valid’ case) between two 2D arrays: You can simply use matrix-multiplication np.dot like so – out = np.dot(arr_one,arr_two.T) Correlation with the default “valid” case between each pairwise row combinations (row1,row2) of the two input arrays would correspond to multiplication result at each (row1,row2) position. Row-wise Correlation Coefficient calculation for two 2D arrays: def … Read more

Moving average or running mean

UPDATE: more efficient solutions have been proposed, uniform_filter1d from scipy being probably the best among the “standard” 3rd-party libraries, and some newer or specialized libraries are available too. You can use np.convolve for that: np.convolve(x, np.ones(N)/N, mode=”valid”) Explanation The running mean is a case of the mathematical operation of convolution. For the running mean, you … Read more

Fitting empirical distribution to theoretical ones with Scipy (Python)?

Distribution Fitting with Sum of Square Error (SSE) This is an update and modification to Saullo’s answer, that uses the full list of the current scipy.stats distributions and returns the distribution with the least SSE between the distribution’s histogram and the data’s histogram. Example Fitting Using the El Niño dataset from statsmodels, the distributions are … Read more