Questions tagged [scipy]

SciPy is an open source library of algorithms and mathematical tools for the Python programming language.

SciPy is an open-source library for the programming language consisting of mathematical algorithms and functions for manipulating and visualizing data, often used in science and engineering. SciPy includes algorithms and tools for tasks such as optimization, clustering, discrete Fourier transforms, linear algebra, signal processing and multi-dimensional image processing.

SciPy is closely related to NumPy and depends on many functions, including a multidimensional array that is used as the basic data structure in SciPy.

SciPy is currently distributed under the BSD license.

Latest stable version:

1.7.3 (2021-11-25)

Documentation:

https://docs.scipy.org/doc/scipy/reference/

21123 questions
88
votes
5 answers

Scikit-learn train_test_split with indices

How do I get the original indices of the data when using train_test_split()? What I have is the following from sklearn.cross_validation import train_test_split import numpy as np data = np.reshape(np.randn(20),(10,2)) # 10 training examples labels =…
CentAu
  • 10,660
  • 15
  • 59
  • 85
88
votes
6 answers

What does .shape[] do in "for i in range(Y.shape[0])"?

I'm trying to break down a program line by line. Y is a matrix of data but I can't find any concrete data on what .shape[0] does exactly. for i in range(Y.shape[0]): if Y[i] == -1: This program uses numpy, scipy, matplotlib.pyplot, and cvxopt.
HipsterCarlGoldstein
  • 1,029
  • 1
  • 9
  • 8
86
votes
12 answers

How to apply piecewise linear fit in Python?

I am trying to fit piecewise linear fit as shown in fig.1 for a data set This figure was obtained by setting on the lines. I attempted to apply a piecewise linear fit using the code: from scipy import optimize import matplotlib.pyplot as plt import…
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86
86
votes
4 answers

Fitting a Normal distribution to 1D data

I have a 1 dimensional array. I can compute the "mean" and "standard deviation" of this sample and plot the "Normal distribution" but I have a problem: I want to plot the data and Normal distribution in the same figure. I dont know how to plot both…
Adel
  • 3,542
  • 8
  • 30
  • 31
86
votes
2 answers

Mesh grid functions in Python (meshgrid mgrid ogrid ndgrid)

I'm looking for a clear comparison of meshgrid-like functions. Unfortunately I don't find it! Numpy http://docs.scipy.org/doc/numpy/reference/ provides mgrid ogrid meshgrid Scitools http://hplgit.github.io/scitools/doc/api/html/index.html…
scls
  • 16,591
  • 10
  • 44
  • 55
84
votes
10 answers

Cannot import scipy.misc.imread

I've seen this problem before with other people, but haven't found a fix. All I'm trying to do is: from scipy.misc import imread and I get /home1/users/joe.borg/ in () ----> 1 from scipy.misc import…
joedborg
  • 17,651
  • 32
  • 84
  • 118
84
votes
7 answers

How does condensed distance matrix work? (pdist)

scipy.spatial.distance.pdist returns a condensed distance matrix. From the documentation: Returns a condensed distance matrix Y. For each and (where ), the metric dist(u=X[i], v=X[j]) is computed and stored in entry ij. I thought ij meant i*j.…
Rafael Almeida
  • 2,377
  • 3
  • 22
  • 32
83
votes
8 answers

How to display progress of scipy.optimize function?

I use scipy.optimize to minimize a function of 12 arguments. I started the optimization a while ago and still waiting for results. Is there a way to force scipy.optimize to display its progress (like how much is already done, what are the current…
Roman
  • 124,451
  • 167
  • 349
  • 456
81
votes
5 answers

How can I get descriptive statistics of a NumPy array?

I use the following code to create a numpy-ndarray. The file has 9 columns. I explicitly type each column: dataset = np.genfromtxt("data.csv", delimiter=",",dtype=('|S1', float, float,float,float,float,float,float,int)) Now I would like to get some…
beta
  • 5,324
  • 15
  • 57
  • 99
80
votes
3 answers

Calculating the area under a curve given a set of coordinates, without knowing the function

I have one list of 100 numbers as height for Y axis, and as length for X axis: 1 to 100 with a constant step of 5. I need to calculate the Area that it is included by the curve of the (x,y) points, and the X axis, using rectangles and Scipy. Do I…
user1640255
  • 1,224
  • 3
  • 19
  • 25
79
votes
6 answers

Factorial in numpy and scipy

How can I import factorial function from numpy and scipy separately in order to see which one is faster? I already imported factorial from python itself by import math. But, it does not work for numpy and scipy.
MOON
  • 2,516
  • 4
  • 31
  • 49
78
votes
3 answers

Optimal way to compute pairwise mutual information using numpy

For an m x n matrix, what's the optimal (fastest) way to compute the mutual information for all pairs of columns (n x n)? By mutual information, I mean: I(X, Y) = H(X) + H(Y) - H(X,Y) where H(X) refers to the Shannon entropy of X. Currently I'm…
nahsivar
  • 1,099
  • 1
  • 10
  • 13
78
votes
3 answers

T-test in Pandas

If I want to calculate the mean of two categories in Pandas, I can do it like this: data = {'Category': ['cat2','cat1','cat2','cat1','cat2','cat1','cat2','cat1','cat1','cat1','cat2'], 'values': [1,2,3,1,2,3,1,2,3,5,1]} my_data =…
hirolau
  • 13,451
  • 8
  • 35
  • 47
77
votes
13 answers

How to install SciPy on Apple Silicon (ARM / M1)

I have successfully installed python 3.9.1 with Numpy and Matplotlib on a new Mac mini with Apple Silicon. However, I cannot install SciPy : I get compilation errors when using python3 -m pip install scipy I also tried installing everything from…
David Sénéchal
  • 937
  • 1
  • 7
  • 4
77
votes
4 answers

Specifying targets for intersphinx links to numpy, scipy, and matplotlib

Following the documentation for setting up Sphinx documentation links between packages, I have added intersphinx_mapping = {'python': ('http://docs.python.org/2', None), 'numpy': ('http://docs.scipy.org/doc/numpy/', None), …
orome
  • 45,163
  • 57
  • 202
  • 418