Does Python SciPy need BLAS?

If you need to use the latest versions of SciPy rather than the packaged version, without going through the hassle of building BLAS and LAPACK, you can follow the below procedure. Install linear algebra libraries from repository (for Ubuntu), sudo apt-get install gfortran libopenblas-dev liblapack-dev Then install SciPy, (after downloading the SciPy source): python setup.py … 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

How to add a new row to an empty numpy array

The way to “start” the array that you want is: arr = np.empty((0,3), int) Which is an empty array but it has the proper dimensionality. >>> arr array([], shape=(0, 3), dtype=int64) Then be sure to append along axis 0: arr = np.append(arr, np.array([[1,2,3]]), axis=0) arr = np.append(arr, np.array([[4,5,6]]), axis=0) But, @jonrsharpe is right. In fact, … Read more

How to normalize a NumPy array to within a certain range?

# Normalize audio channels to between -1.0 and +1.0 audio /= np.max(np.abs(audio),axis=0) # Normalize image to between 0 and 255 image *= (255.0/image.max()) Using /= and *= allows you to eliminate an intermediate temporary array, thus saving some memory. Multiplication is less expensive than division, so image *= 255.0/image.max() # Uses 1 division and image.size … Read more

What are the differences between Pandas and NumPy+SciPy in Python? [closed]

pandas provides high level data manipulation tools built on top of NumPy. NumPy by itself is a fairly low-level tool, similar to MATLAB. pandas on the other hand provides rich time series functionality, data alignment, NA-friendly statistics, groupby, merge and join methods, and lots of other conveniences. It has become very popular in recent years … Read more

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

How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting

For fitting y = A + B log x, just fit y against (log x). >>> x = numpy.array([1, 7, 20, 50, 79]) >>> y = numpy.array([10, 19, 30, 35, 51]) >>> numpy.polyfit(numpy.log(x), y, 1) array([ 8.46295607, 6.61867463]) # y ā‰ˆ 8.46 log(x) + 6.62 For fitting y = AeBx, take the logarithm of both … Read more

Calculating Pearson correlation and significance in Python

You can have a look at scipy.stats: from pydoc import help from scipy.stats.stats import pearsonr help(pearsonr) >>> Help on function pearsonr in module scipy.stats.stats: pearsonr(x, y) Calculates a Pearson correlation coefficient and the p-value for testing non-correlation. The Pearson correlation coefficient measures the linear relationship between two datasets. Strictly speaking, Pearson’s correlation requires that each … Read more