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
77
votes
2 answers

Multiple variables in SciPy's optimize.minimize

According to the SciPy documentation, it is possible to minimize functions with multiple variables, yet it doesn't say how to optimize such functions. from scipy.optimize import minimize from math import * def f(c): return sqrt((sin(pi/2) +…
Henrik Hansen
  • 2,180
  • 1
  • 14
  • 19
76
votes
7 answers

Convert Z-score (Z-value, standard score) to p-value for normal distribution in Python

How does one convert a Z-score from the Z-distribution (standard normal distribution, Gaussian distribution) to a p-value? I have yet to find the magical function in Scipy's stats module to do this, but one must be there.
gotgenes
  • 38,661
  • 28
  • 100
  • 128
75
votes
3 answers

What is the difference between numpy.fft and scipy.fftpack?

Is the later just a synonym of the former, or are they two different implementations of FFT? Which one is better?
Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
75
votes
6 answers

How do I plot list of tuples in Python?

I have the following data set. I would like to use Python or Gnuplot to plot the data. The tuples are of the form (x, y). The Y-axis should be a log axis, that is, log(y). A scatter plot or line plot would be ideal. How can this be done? [(0,…
olliepower
  • 1,269
  • 2
  • 11
  • 17
73
votes
1 answer

Working with big data in python and numpy, not enough ram, how to save partial results on disc?

I am trying to implement algorithms for 1000-dimensional data with 200k+ datapoints in python. I want to use numpy, scipy, sklearn, networkx, and other useful libraries. I want to perform operations such as pairwise distance between all of the…
Ekgren
  • 1,024
  • 1
  • 9
  • 13
72
votes
4 answers

Share axes in matplotlib for only part of the subplots

I am having a big plot where I initiated with: import numpy as np import matplotlib.pyplot as plt fig, axs = plt.subplots(5, 4) And I want to do share-x-axis between column 1 and 2; and do the same between column 3 and 4. However, column 1 and 2…
Yuxiang Wang
  • 8,095
  • 13
  • 64
  • 95
72
votes
10 answers

Multivariate normal density in Python?

Is there any python package that allows the efficient computation of the PDF (probability density function) of a multivariate normal distribution? It doesn't seem to be included in Numpy/Scipy, and surprisingly a Google search didn't turn up any…
Benno
  • 5,288
  • 5
  • 42
  • 60
71
votes
5 answers

How to filter numpy array by list of indices?

I have a numpy array, filtered__rows, comprised of LAS data [x, y, z, intensity, classification]. I have created a cKDTree of points and have found nearest neighbors, query_ball_point, which is a list of indices for the point and its neighbors. Is…
Barbarossa
  • 1,045
  • 5
  • 14
  • 24
70
votes
3 answers

python numpy/scipy curve fitting

I have some points and I am trying to fit curve for this points. I know that there exist scipy.optimize.curve_fit function, but I do not understand the documentation, i.e. how to use this function. My points: np.array([(1, 1), (2, 4), (3, 1), (9,…
Bob
  • 10,427
  • 24
  • 63
  • 71
69
votes
5 answers

Python curve_fit with multiple independent variables

Python's curve_fit calculates the best-fit parameters for a function with a single independent variable, but is there a way, using curve_fit or something else, to fit for a function with multiple independent variables? For example: def func(x, y, a,…
ylangylang
  • 3,294
  • 11
  • 30
  • 34
69
votes
3 answers

Colorize Voronoi Diagram

I'm trying to colorize a Voronoi Diagram created using scipy.spatial.Voronoi. Here's my code: import numpy as np import matplotlib.pyplot as plt from scipy.spatial import Voronoi, voronoi_plot_2d # make up data points points =…
moooeeeep
  • 31,622
  • 22
  • 98
  • 187
69
votes
5 answers

Vectorized way of calculating row-wise dot product two matrices with Scipy

I want to calculate the row-wise dot product of two matrices of the same dimension as fast as possible. This is the way I am doing it: import numpy as np a = np.array([[1,2,3], [3,4,5]]) b = np.array([[1,2,3], [1,2,3]]) result = np.array([]) for…
Cupitor
  • 11,007
  • 19
  • 65
  • 91
67
votes
3 answers

How to understand numpy strides for layman?

I am currently going through numpy and there is a topic in numpy called "strides". I understand what it is. But how does it work? I did not find any useful information online. Can anyone let me understand in a layman's terms?
Atif
  • 1,012
  • 1
  • 9
  • 23
66
votes
4 answers

Convert ndarray from float64 to integer

I've got an ndarray in python with a dtype of float64. I'd like to convert the array to be an array of integers. How should I do this? int() won't work, as it says it can't convert it to a scalar. Changing the dtype field itself obviously doesn't…
robintw
  • 27,571
  • 51
  • 138
  • 205
66
votes
5 answers

How to access sparse matrix elements?

type(A) A.shape (8529, 60877) print A[0,:] (0, 25) 1.0 (0, 7422) 1.0 (0, 26062) 1.0 (0, 31804) 1.0 (0, 41602) 1.0 (0, 43791) 1.0 print A[1,:] (0, 7044) 1.0 (0, 31418) 1.0 (0,…
siamii
  • 23,374
  • 28
  • 93
  • 143