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
41
votes
6 answers

scipy.io.loadmat nested structures (i.e. dictionaries)

Using the given routines (how to load Matlab .mat files with scipy), I could not access deeper nested structures to recover them into dictionaries To present the problem I run into in more detail, I give the following toy example: load scipy.io as…
mergen
  • 1,081
  • 1
  • 9
  • 10
41
votes
4 answers

Official abbreviation for: import scipy as sp/sc

I've seen both: import scipy as sp and: import scipy as sc Is there an official preference listed anywhere? For example, in the Introduction of the Scipy documentation, it is recommended to import numpy as np import matplotlib as mpl import…
DanHickstein
  • 6,588
  • 13
  • 54
  • 90
41
votes
4 answers

Fitting a closed curve to a set of points

I have a set of points pts which form a loop and it looks like this: This is somewhat similar to 31243002, but instead of putting points in between pairs of points, I would like to fit a smooth curve through the points (coordinates are given at the…
Mahdi
  • 3,188
  • 2
  • 20
  • 33
41
votes
2 answers

NumPy and SciPy - Difference between .todense() and .toarray()

I am wondering if there is any difference (advantage/disadvantage) of using .toarray() vs. .todense() on sparse NumPy arrays. E.g., import scipy as sp import numpy as np sparse_m = sp.sparse.bsr_matrix(np.array([[1,0,0,0,1], [1,0,0,0,1]])) %timeit…
user2489252
41
votes
7 answers

Highest Posterior Density Region and Central Credible Region

Given a posterior p(Θ|D) over some parameters Θ, one can define the following: Highest Posterior Density Region: The Highest Posterior Density Region is the set of most probable values of Θ that, in total, constitute 100(1-α) % of the posterior…
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
41
votes
3 answers

What is a "scalar" in NumPy?

The documentation states the purpose of scalars, such as the fact that conventional Python numbers like float and integer are too primitive, and therefore more complex data types are necessary. It also states certain kinds of scalars (data type…
chopper draw lion4
  • 12,401
  • 13
  • 53
  • 100
41
votes
5 answers

interpolate 3D volume with numpy and or scipy

I am extremely frustrated because after several hours I can't seem to be able to do a seemingly easy 3D interpolation in python. In Matlab all I had to do was Vi = interp3(x,y,z,V,xi,yi,zi) What is the exact equivalent of this using scipy's…
user1301295
  • 674
  • 1
  • 6
  • 15
41
votes
1 answer

Tutorial for scipy.cluster.hierarchy

I'm trying to understand how to manipulate a hierarchy cluster but the documentation is too ... technical?... and I can't understand how it works. Is there any tutorial that can help me to start with, explaining step by step some simple…
user2988577
  • 3,997
  • 7
  • 21
  • 21
41
votes
1 answer

Scipy sparse matrices - purpose and usage of different implementations

Scipy has many different types of sparse matrices available. What are the most important differences between these types, and what is the difference in their intended usage? I'm developing a code in python based on a sample code1 in Matlab. One…
DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
41
votes
10 answers

Map each list value to its corresponding percentile

I'd like to create a function that takes a (sorted) list as its argument and outputs a list containing each element's corresponding percentile. For example, fn([1,2,3,4,17]) returns [0.0, 0.25, 0.50, 0.75, 1.00]. Can anyone please either: Help me…
Jubbles
  • 4,450
  • 8
  • 35
  • 47
41
votes
4 answers

Evaluate sympy expression from an array of values

I'm experimenting with sympy and I've hit upon an issue I can't work out. Using scipy I can write an expression and evaluate it for an array of x values as follows: import scipy xvals = scipy.arange(-100,100,0.1) f = lambda x: x**2 f(xvals) Using…
mgoi
  • 413
  • 1
  • 4
  • 4
40
votes
4 answers

Is there an efficient way of concatenating scipy.sparse matrices?

I'm working with some rather large sparse matrices (from 5000x5000 to 20000x20000) and need to find an efficient way to concatenate matrices in a flexible way in order to construct a stochastic matrix from separate parts. Right now I'm using the…
jones
  • 543
  • 1
  • 4
  • 7
40
votes
4 answers

Efficiently create sparse pivot tables in pandas?

I'm working turning a list of records with two columns (A and B) into a matrix representation. I have been using the pivot function within pandas, but the result ends up being fairly large. Does pandas support pivoting into a sparse format? I know I…
neelshiv
  • 6,125
  • 6
  • 21
  • 35
39
votes
3 answers

How to force zero interception in linear regression?

I have some more or less linear data of the form: x = [0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 2.0, 4.0, 6.0, 8.0, 10.0, 20.0, 40.0, 60.0, 80.0] y = [0.50505332505407008, 1.1207373784533172, 2.1981844719020001, 3.1746209003398689, 4.2905482471260044,…
Kyra Tafar
  • 393
  • 1
  • 3
  • 4
39
votes
10 answers

pyinstaller creating EXE RuntimeError: maximum recursion depth exceeded while calling a Python object

I am running WinPython 3.4.4.3 with pyinstaller 3.2 (obtained via pip install pyinstaller). Now I've got some really simple Qt4 code that I want to convert to EXE and I've run into problem that I cannot solve. The Code: import sys import math from…
H_Four
  • 501
  • 1
  • 5
  • 6