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
33
votes
4 answers

Scipy/Numpy FFT Frequency Analysis

I'm looking for how to turn the frequency axis in a fft (taken via scipy.fftpack.fftfreq) into a frequency in Hertz, rather than bins or fractional bins. I tried to code below to test out the FFT: t = scipy.linspace(0,120,4000) acc = lambda t:…
nathan lachenmyer
  • 5,298
  • 8
  • 36
  • 57
33
votes
7 answers

How do I get a lognormal distribution in Python with Mu and Sigma?

I have been trying to get the result of a lognormal distribution using Scipy. I already have the Mu and Sigma, so I don't need to do any other prep work. If I need to be more specific (and I am trying to be with my limited knowledge of stats), I…
Eric Lubow
  • 763
  • 2
  • 12
  • 30
33
votes
4 answers

ndimage missing from scipy

I'm trying to use the ndimage library from scipy, but its apparently missing. I have run the tests from both numpy and scipy and the results were OK. I am using numpy 1.6.1 and scipy 0.10.0 installed from the official packages on…
davidtbernal
  • 13,434
  • 9
  • 44
  • 60
33
votes
5 answers

python numpy euclidean distance calculation between matrices of row vectors

I am new to Numpy and I would like to ask you how to calculate euclidean distance between points stored in a vector. Let's assume that we have a numpy.array each row is a vector and a single numpy.array. I would like to know if it is possible to…
pacodelumberg
  • 2,214
  • 4
  • 25
  • 32
33
votes
7 answers

Overflow Error in Python's numpy.exp function

I want to use numpy.exp like this: cc = np.array([ [0.120,0.34,-1234.1] ]) print 1/(1+np.exp(-cc)) But this gives me error: /usr/local/lib/python2.7/site-packages/ipykernel/__main__.py:5: RuntimeWarning: overflow encountered in exp I can't…
Fcoder
  • 9,066
  • 17
  • 63
  • 100
33
votes
8 answers

How to perform cubic spline interpolation in python?

I have two lists to describe the function y(x): x = [0,1,2,3,4,5] y = [12,14,22,39,58,77] I would like to perform cubic spline interpolation so that given some value u in the domain of x, e.g. u = 1.25 I can find y(u). I found this in SciPy but I…
user112829
  • 491
  • 1
  • 4
  • 7
33
votes
2 answers

Reordering matrix elements to reflect column and row clustering in naiive python

I'm looking for a way to perform clustering separately on matrix rows and than on its columns, reorder the data in the matrix to reflect the clustering and putting it all together. The clustering problem is easily solvable, so is the dendrogram…
Boris Gorelik
  • 29,945
  • 39
  • 128
  • 170
33
votes
4 answers

Obtaining values used in boxplot, using python and matplotlib

I can draw a boxplot from data: import numpy as np import matplotlib.pyplot as plt data = np.random.rand(100) plt.boxplot(data) Then, the box will range from the 25th-percentile to 75th-percentile, and the whisker will range from the smallest…
Yuxiang Wang
  • 8,095
  • 13
  • 64
  • 95
33
votes
2 answers

Exponential curve fitting in SciPy

I have two NumPy arrays x and y. When I try to fit my data using exponential function and curve_fit (SciPy) with this simple code #!/usr/bin/env python from pylab import * from scipy.optimize import curve_fit x = np.array([399.75, 989.25, 1578.75,…
drastega
  • 1,581
  • 5
  • 30
  • 42
32
votes
1 answer

scipy.special import issue

I have an issue with importing the scipy.special package. It isn't harmful, just annoying/interesting. When I import scipy using import scipy as sp and then try to access sp.special I get: >>> import scipy as sp >>> sp.special Traceback (most recent…
Iain Rist
  • 976
  • 2
  • 9
  • 18
32
votes
3 answers

expanding (adding a row or column) a scipy.sparse matrix

Suppose I have a NxN matrix M (lil_matrix or csr_matrix) from scipy.sparse, and I want to make it (N+1)xN where M_modified[i,j] = M[i,j] for 0 <= i < N (and all j) and M[N,j] = 0 for all j. Basically, I want to add a row of zeros to the bottom of M…
RandomGuy
  • 1,658
  • 4
  • 18
  • 21
32
votes
4 answers

Restrict scipy.optimize.minimize to integer values

I'm using scipy.optimize.minimize to optimize a real-world problem for which the answers can only be integers. My current code looks like this: from scipy.optimize import minimize def f(x): return…
nicmet
  • 510
  • 1
  • 5
  • 9
32
votes
2 answers

Read a large csv into a sparse pandas dataframe in a memory efficient way

The pandas read_csv function doesn't seem to have a sparse option. I have csv data with a ton of zeros in it (it compresses very well, and stripping out any 0 value reduces it to almost half the original size). I've tried loading it into a dense…
32
votes
2 answers

Check if two scipy.sparse.csr_matrix are equal

I want to check if two csr_matrix are equal. If I do: x.__eq__(y) I get: raise ValueError("The truth value of an array with more than one " ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or…
AvidLearner
  • 4,123
  • 5
  • 35
  • 48
32
votes
6 answers

Python baseline correction library

I am currently working with some Raman Spectra data, and I am trying to correct my data caused by florescence skewing. Take a look at the graph below: I am pretty close to achieving what I want. As you can see, I am trying to fit a polynomial in…
Tinker
  • 4,165
  • 6
  • 33
  • 72