Questions tagged [scipy]
SciPy is an open source library of algorithms and mathematical tools for the Python programming language.
20,945
questions
552
votes
14
answers
1.2m
views
How do I read CSV data into a record array in NumPy?
Is there a direct way to import the contents of a CSV file into a record array, just like how R's read.table(), read.delim(), and read.csv() import data into R dataframes?
Or should I use csv.reader() ...
548
votes
16
answers
679k
views
Read .mat files in Python
Is it possible to read binary MATLAB .mat files in Python?
I've seen that SciPy has alleged support for reading .mat files, but I'm unsuccessful with it. I installed SciPy version 0.7.0, and I can't ...
500
votes
16
answers
497k
views
Sorting arrays in NumPy by column
How do I sort a NumPy array by its nth column?
For example, given:
a = array([[9, 2, 3],
[4, 5, 6],
[7, 0, 5]])
I want to sort the rows of a by the second column to obtain:
...
316
votes
27
answers
1.4m
views
Error "Import Error: No module named numpy" on Windows
I have a very similar question to this question, but I am still one step behind. I have only one version of Python 3 installed on my Windows 7 (sorry) 64-bit system.
I installed NumPy following this ...
303
votes
10
answers
144k
views
Does Conda replace the need for virtualenv?
I recently discovered Conda after I was having trouble installing SciPy, specifically on a Heroku app that I am developing.
With Conda you create environments, very similar to what virtualenv does. ...
291
votes
30
answers
598k
views
Moving average or running mean
Is there a SciPy function or NumPy function or module for Python that calculates the running mean of a 1D array given a specific window?
291
votes
12
answers
488k
views
How to smooth a curve in the right way?
Lets assume we have a dataset which might be given approximately by
import numpy as np
x = np.linspace(0,2*np.pi,100)
y = np.sin(x) + np.random.random(100) * 0.2
Therefore we have a variation of 20% ...
278
votes
8
answers
57k
views
Relationship between SciPy and NumPy
SciPy appears to provide most (but not all [1]) of NumPy's functions in its own namespace. In other words, if there's a function named numpy.foo, there's almost certainly a scipy.foo. Most of the time,...
254
votes
14
answers
482k
views
Is there a library function for Root mean square error (RMSE) in python?
I know I could implement a root mean squared error function like this:
def rmse(predictions, targets):
return np.sqrt(((predictions - targets) ** 2).mean())
What I'm looking for if this rmse ...
230
votes
7
answers
431k
views
How to add a new row to an empty numpy array
Using standard Python arrays, I can do the following:
arr = []
arr.append([1,2,3])
arr.append([4,5,6])
# arr is now [[1,2,3],[4,5,6]]
However, I cannot do the same thing in numpy. For example:
arr =...
228
votes
7
answers
431k
views
How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting
I have a set of data and I want to compare which line describes it best (polynomials of different orders, exponential or logarithmic).
I use Python and Numpy and for polynomial fitting there is a ...
222
votes
19
answers
446k
views
Calculating Pearson correlation and significance in Python
I am looking for a function that takes as input two lists, and returns the Pearson correlation, and the significance of the correlation.
214
votes
8
answers
460k
views
How to normalize a NumPy array to within a certain range?
After doing some processing on an audio or image array, it needs to be normalized within a range before it can be written back to a file. This can be done like so:
# Normalize audio channels to ...
211
votes
15
answers
377k
views
Installing SciPy with pip
It is possible to install NumPy with pip using pip install numpy.
Is there a similar possibility with SciPy? (Doing pip install scipy does not work.)
Update
The package SciPy is now available to ...
206
votes
3
answers
138k
views
What are the differences between Pandas and NumPy+SciPy in Python? [closed]
They both seem exceedingly similar and I'm curious as to which package would be more beneficial for financial data analysis.
191
votes
13
answers
204k
views
Fitting empirical distribution to theoretical ones with Scipy (Python)?
INTRODUCTION: I have a list of more than 30,000 integer values ranging from 0 to 47, inclusive, e.g.[0,0,0,0,..,1,1,1,1,...,2,2,2,2,...,47,47,47,...] sampled from some continuous distribution. The ...
187
votes
30
answers
401k
views
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
I'm trying to install scipy via pip on my 64 bit ARMV8 board. I have already installed openblas which is required by scipy. So, no issues with that. When i gave pip3 install scipy --trusted-host pypi....
185
votes
10
answers
380k
views
Numpy Resize/Rescale Image
I would like to take an image and change the scale of the image, while it is a numpy array.
For example I have this image of a coca-cola bottle:
bottle-1
Which translates to a numpy array of shape (...
185
votes
2
answers
203k
views
How do I use numpy.where()? What should I pass, and what does the result mean? [closed]
I tried reading the documentation for numpy.where(), but I'm still confused.
What should I pass for the condition, x and y values? When I pass only condition, what does the result mean and how can I ...
184
votes
7
answers
127k
views
Does Python SciPy need BLAS?
numpy.distutils.system_info.BlasNotFoundError:
Blas (http://www.netlib.org/blas/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site....
184
votes
10
answers
226k
views
Peak-finding algorithm for Python/SciPy
I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?
My ...
183
votes
6
answers
156k
views
Numpy: Divide each row by a vector element
Suppose I have a numpy array:
data = np.array([[1,1,1],[2,2,2],[3,3,3]])
and I have a corresponding "vector:"
vector = np.array([1,2,3])
How do I operate on data along each row to either subtract ...
180
votes
6
answers
329k
views
Compute a confidence interval from sample data
I have sample data which I would like to compute a confidence interval for, assuming a normal distribution.
I have found and installed the numpy and scipy packages and have gotten numpy to return a ...
179
votes
18
answers
305k
views
scipy.misc module has no attribute imread?
I am trying to read an image with scipy. However it does not accept the scipy.misc.imread part. What could be the cause of this?
>>> import scipy
>>> scipy.misc
<module 'scipy....
176
votes
2
answers
331k
views
A tool to convert MATLAB code to Python [closed]
I have a bunch of MATLAB code from my MS thesis which I now want to convert to Python (using numpy/scipy and matplotlib) and distribute as open-source. I know the similarity between MATLAB and Python ...
169
votes
3
answers
226k
views
Should I use scipy.pi, numpy.pi, or math.pi?
In a project using SciPy and NumPy, should I use scipy.pi, numpy.pi, or math.pi?
161
votes
8
answers
235k
views
Installing SciPy and NumPy using pip
I'm trying to create required libraries in a package I'm distributing. It requires both the SciPy and NumPy libraries.
While developing, I installed both using
apt-get install scipy
which installed ...
158
votes
6
answers
333k
views
How to create a density plot
In R I can create the desired output by doing:
data = c(rep(1.5, 7), rep(2.5, 2), rep(3.5, 8),
rep(4.5, 3), rep(5.5, 1), rep(6.5, 8))
plot(density(data, bw=0.5))
In python (with matplotlib)...
152
votes
15
answers
234k
views
Multiple linear regression in Python
I can't seem to find any python libraries that do multiple regression. The only things I find only do simple regression. I need to regress my dependent variable (y) against several independent ...
148
votes
3
answers
81k
views
Confusion between numpy, scipy, matplotlib and pylab
Numpy, scipy, matplotlib, and pylab are common terms among they who use python for scientific computation.
I just learn a bit about pylab, and I got confused.
Whenever I want to import numpy, I can ...
141
votes
6
answers
248k
views
binning data in python with scipy/numpy
is there a more efficient way to take an average of an array in prespecified bins? for example, i have an array of numbers and an array corresponding to bin start and end positions in that array, and ...
138
votes
5
answers
92k
views
How to check BLAS/LAPACK linkage in NumPy and SciPy?
I am builing my numpy/scipy environment based on blas and lapack more or less based on this walk through.
When I am done, how can I check, that my numpy/scipy functions really do use the previously ...
136
votes
20
answers
284k
views
Can't install Scipy through pip
When installing scipy through pip with :
pip install scipy
Pip fails to build scipy and throws the following error:
Cleaning up...
Command /Users/administrator/dev/KaggleAux/env/bin/python2.7 -c "...
136
votes
8
answers
223k
views
How to calculate cumulative normal distribution?
I am looking for a function in Numpy or Scipy (or any rigorous Python library) that will give me the cumulative normal distribution function in Python.
131
votes
13
answers
330k
views
ImportError in importing from sklearn: cannot import name check_build
I am getting the following error while trying to import from sklearn:
>>> from sklearn import svm
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
...
130
votes
7
answers
427k
views
Plotting a fast Fourier transform in Python
I have access to NumPy and SciPy and want to create a simple FFT of a data set. I have two lists, one that is y values and the other is timestamps for those y values.
What is the simplest way to feed ...
125
votes
3
answers
221k
views
How to get the indices list of all NaN value in numpy array?
Say now I have a numpy array which is defined as,
[[1,2,3,4],
[2,3,NaN,5],
[NaN,5,2,3]]
Now I want to have a list that contains all the indices of the missing values, which is [(1,2),(2,0)] at this ...
122
votes
10
answers
295k
views
How to calculate probability in a normal distribution given mean & standard deviation?
How to calculate probability in normal distribution given mean, std in Python? I can always explicitly code my own function according to the definition like the OP in this question did: Calculating ...
121
votes
7
answers
185k
views
Histogram Matplotlib
So I have a little problem. I have a data set in scipy that is already in the histogram format, so I have the center of the bins and the number of events per bin. How can I now plot is as a histogram. ...
121
votes
1
answer
43k
views
How can I perform two-dimensional interpolation using scipy?
This Q&A is intended as a canonical(-ish) concerning two-dimensional (and multi-dimensional) interpolation using scipy. There are often questions concerning the basic syntax of various ...
115
votes
11
answers
100k
views
Principal component analysis in Python
I'd like to use principal component analysis (PCA) for dimensionality reduction. Does numpy or scipy already have it, or do I have to roll my own using numpy.linalg.eigh?
I don't just want to use ...
113
votes
17
answers
462k
views
ImportError: No module named scipy
I am using Python 2.7 and trying to get PyBrain to work.
But I get this error even though scipy is installed -
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
112
votes
13
answers
124k
views
scipy: savefig without frames, axes, only content
In numpy/scipy I have an image stored in an array. I can display it, I want to save it using savefig without any borders, axes, labels, titles,... Just pure image, nothing else.
I want to avoid ...
111
votes
9
answers
193k
views
Quantile-Quantile Plot using SciPy
How would you create a qq-plot using Python?
Assuming that you have a large set of measurements and are using some plotting function that takes XY-values as input. The function should plot the ...
110
votes
3
answers
108k
views
Two-sample Kolmogorov-Smirnov Test in Python Scipy
I can't figure out how to do a Two-sample KS test in Scipy.
After reading the documentation of scipy kstest, I can see how to test whether a distribution is identical to standard normal distribution
...
109
votes
4
answers
164k
views
How to transform numpy.matrix or array to scipy sparse matrix
For SciPy sparse matrix, one can use todense() or toarray() to transform to NumPy matrix or array. What are the functions to do the inverse?
I searched, but got no idea what keywords should be the ...
106
votes
3
answers
221k
views
How to implement band-pass Butterworth filter with Scipy.signal.butter
UPDATE:
I found a Scipy Recipe based in this question! So, for anyone interested, go straight to: Contents » Signal processing » Butterworth Bandpass
I'm having a hard time to achieve what seemed ...
105
votes
3
answers
185k
views
How to calculate the inverse of the normal cumulative distribution function in python?
How do I calculate the inverse of the cumulative distribution function (CDF) of the normal distribution in Python?
Which library should I use? Possibly scipy?
104
votes
1
answer
228k
views
Creating lowpass filter in SciPy - understanding methods and units
I am trying to filter a noisy heart rate signal with python. Because heart rates should never be above about 220 beats per minute, I want to filter out all noise above 220 bpm. I converted 220/minute ...
103
votes
8
answers
272k
views
How to delete columns in numpy.array
I would like to delete selected columns in a numpy.array . This is what I do:
n [397]: a = array([[ NaN, 2., 3., NaN],
.....: [ 1., 2., 3., 9]])
In [398]: print a
[[ NaN 2. 3. ...