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
37
votes
5 answers

How is a Pandas crosstab different from a Pandas pivot_table?

Both the pandas.crosstab and the Pandas pivot table seem to provide the exact same functionality. Are there any differences?
user1008537
37
votes
5 answers

Fitting a gamma distribution with (python) Scipy

Can anyone help me out in fitting a gamma distribution in python? Well, I've got some data : X and Y coordinates, and I want to find the gamma parameters that fit this distribution... In the Scipy doc, it turns out that a fit method actually exists…
Archanimus
  • 371
  • 1
  • 3
  • 3
37
votes
1 answer

How to plot a 3D density map in python with matplotlib

I have a large dataset of (x,y,z) protein positions and would like to plot areas of high occupancy as a heatmap. Ideally the output should look similiar to the volumetric visualisation below, but I'm not sure how to achieve this with matplotlib.…
nv_wu
  • 1,045
  • 1
  • 13
  • 24
37
votes
5 answers

Parse a Pandas column to Datetime when importing table from SQL database and filtering rows by date

I have a DataFrame with column named date. How can we convert/parse the 'date' column to a DateTime object? I loaded the date column from a Postgresql database using sql.read_frame(). An example of the date column is 2013-04-04. What I am trying to…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
37
votes
8 answers

Bézier curve fitting with SciPy

I have a set of points which approximate a 2D curve. I would like to use Python with numpy and scipy to find a cubic Bézier path which approximately fits the points, where I specify the exact coordinates of two endpoints, and it returns the…
Craig Baker
  • 481
  • 1
  • 4
  • 7
36
votes
4 answers

Get coordinates of local maxima in 2D array above certain value

from PIL import Image import numpy as np from scipy.ndimage.filters import maximum_filter import pylab # the picture (256 * 256 pixels) contains bright spots of which I wanna get positions # problem: data has high background around value 900 -…
feinmann
  • 1,060
  • 1
  • 14
  • 20
36
votes
2 answers

making square axes plot with log2 scales in matplotlib

I'd like to make a square axis scatter plot with matplotlib. Normally using set_scale("log") works great, but it limits me to log10. I'd like to make the plot in log2. I saw the solution here: How to produce an exponentially scaled axis? but it is…
user248237
36
votes
1 answer

Determining the byte size of a scipy.sparse matrix?

Is it possible to determine the byte size of a scipy.sparse matrix? In NumPy you can determine the size of an array by doing the following: import numpy as np print(np.zeros((100, 100, 100).nbytes) 8000000
ebressert
  • 2,319
  • 4
  • 21
  • 27
35
votes
10 answers

Calculating Slopes in Numpy (or Scipy)

I am trying to find the fastest and most efficient way to calculate slopes using Numpy and Scipy. I have a data set of three Y variables and one X variable and I need to calculate their individual slopes. For example, I can easily do this one row at…
hotshotiguana
  • 1,520
  • 2
  • 26
  • 40
35
votes
3 answers

Python out of memory on large CSV file (numpy)

I have a 3GB CSV file that I try to read with python, I need the median column wise. from numpy import * def data(): return genfromtxt('All.csv',delimiter=',') data = data() # This is where it fails already. med = zeros(len(data[0])) data =…
Ihmahr
  • 1,110
  • 1
  • 16
  • 25
35
votes
2 answers

How to correctly use scipy's skew and kurtosis functions?

The skewness is a parameter to measure the symmetry of a data set and the kurtosis to measure how heavy its tails are compared to a normal distribution, see for example here. scipy.stats provides an easy way to calculate these two quantities, see…
Alf
  • 1,821
  • 3
  • 30
  • 48
35
votes
4 answers

Show confidence limits and prediction limits in scatter plot

I have two arrays of data for height and weight: import numpy as np, matplotlib.pyplot as plt heights = np.array([50,52,53,54,58,60,62,64,66,67,68,70,72,74,76,55,50,45,65]) weights =…
Eric Bal
  • 1,115
  • 3
  • 12
  • 16
35
votes
9 answers

pandas columns correlation with statistical significance

What is the best way, given a pandas dataframe, df, to get the correlation between its columns df.1 and df.2? I do not want the output to count rows with NaN, which pandas built-in correlation does. But I also want it to output a pvalue or a…
wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
35
votes
3 answers

Getting the r-squared value using curve_fit

I am a beginner with both Python and all its libs. But I have managed to make a small program that works as intended. It takes a string, counts the occurence of the different letters and plots them in a graph and then applies a equation and its…
Mathias
  • 578
  • 2
  • 8
  • 15
35
votes
3 answers

Populate a Pandas SparseDataFrame from a SciPy Sparse Matrix

I noticed Pandas now has support for Sparse Matrices and Arrays. Currently, I create DataFrame()s like this: return DataFrame(matrix.toarray(), columns=features, index=observations) Is there a way to create a SparseDataFrame() with a…
Will
  • 24,082
  • 14
  • 97
  • 108