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
56
votes
3 answers

How to display a 3D plot of a 3D array isosurface with mplot3D or similar

I have a 3-dimensional numpy array. I'd like to display (in matplotlib) a nice 3D plot of an isosurface of this array (or more strictly, display an isosurface of the 3D scalar field defined by interpolating between the sample points). matplotlib's…
timday
  • 24,582
  • 12
  • 83
  • 135
55
votes
7 answers

scipy csr_matrix: understand indptr

Every once in a while, I get to manipulate a csr_matrix but I always forget how the parameters indices and indptr work together to build a sparse matrix. I am looking for a clear and intuitive explanation on how the indptr interacts with both the…
Tanguy
  • 3,124
  • 4
  • 21
  • 29
55
votes
2 answers

Generating a dense matrix from a sparse matrix in numpy python

I have a Sqlite database that contains following type of schema: termcount(doc_num, term , count) This table contains terms with their respective counts in the document. like (doc1 , term1 ,12) (doc1, term 22, 2) . . (docn,term1 , 10) This matrix…
user2374515
54
votes
2 answers

What do all the distributions available in scipy.stats look like?

Visualizing scipy.stats distributions A histogram can be made of the scipy.stats normal random variable to see what the distribution looks like. % matplotlib inline import pandas as pd import scipy.stats as stats d = stats.norm() rv =…
tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
54
votes
2 answers

plotting results of hierarchical clustering on top of a matrix of data

How can I plot a dendrogram right on top of a matrix of values, reordered appropriately to reflect the clustering, in Python? An example is the following figure: This is Figure 6 from: A panel of induced pluripotent stem cells from chimpanzees: a…
user248237
54
votes
6 answers

How to perform two-sample one-tailed t-test with numpy/scipy

In R, it is possible to perform two-sample one-tailed t-test simply by using > A = c(0.19826790, 1.36836629, 1.37950911, 1.46951540, 1.48197798, 0.07532846) > B = c(0.6383447, 0.5271385, 1.7721380, 1.7817880) > t.test(A, B, alternative="greater") …
Timo
  • 5,188
  • 6
  • 35
  • 38
53
votes
3 answers

Scipy sparse... arrays?

So, I'm doing some Kmeans classification using numpy arrays that are quite sparse-- lots and lots of zeroes. I figured that I'd use scipy's 'sparse' package to reduce the storage overhead, but I'm a little confused about how to create arrays, not…
spitzanator
  • 1,877
  • 4
  • 19
  • 29
53
votes
3 answers

sampling random floats on a range in numpy

How can I sample random floats on an interval [a, b] in numpy? Not just integers, but any real numbers. For example, random_float(5, 10) would return random numbers between [5, 10]. thanks.
user248237
52
votes
2 answers

LCP with sparse matrix

I indicate matrices by capital letters, and vectors by small letters. I need to solve the following system of linear inequalities for vector v: min(rv - (u + Av), v - s) = 0 where 0 is a vector of zeros. where r is a scalar, u and s are vectors,…
FooBar
  • 15,724
  • 19
  • 82
  • 171
52
votes
6 answers

Iterating through a scipy.sparse vector (or matrix)

I'm wondering what the best way is to iterate nonzero entries of sparse matrices with scipy.sparse. For example, if I do the following: from scipy.sparse import lil_matrix x = lil_matrix( (20,1) ) x[13,0] = 1 x[15,0] = 2 c = 0 for i in x: print…
RandomGuy
  • 1,658
  • 4
  • 18
  • 21
52
votes
3 answers

Correct way to obtain confidence interval with scipy

I have a 1-dimensional array of data: a = np.array([1,2,3,4,4,4,5,5,5,5,4,4,4,6,7,8]) for which I want to obtain the 68% confidence interval (ie: the 1 sigma). The first comment in this answer states that this can be achieved using…
Gabriel
  • 40,504
  • 73
  • 230
  • 404
52
votes
3 answers

Cannot use scipy.stats

I get an errr when using scipy.stats. in a script after importing scipy. AttributeError: 'module' object has no attribute 'stats' Within script editor I can click on stats after typing scipy. from the pulldown menu, within python console I can not…
user3276418
  • 1,777
  • 4
  • 20
  • 29
52
votes
4 answers

scipy.stats seed?

I am trying to generate scipy.stats.pareto.rvs(b, loc=0, scale=1, size=1) with different seed. In numpy we can seed using numpy.random.seed(seed=233423). Is there any way to seed the random number generated by scipy stats. Note: I am not using numpy…
ashok
  • 625
  • 1
  • 5
  • 5
51
votes
2 answers

Prevent anti-aliasing for imshow in matplotlib

When I use matplotlib's imshow() method to represent a small numpy matrix, it ends up doing some smoothing between pixels. Is there any way to disables this? It makes my figure's misleading in presentations. The figure above is a 28x28 image, so I…
Christopher Dorian
  • 2,163
  • 5
  • 21
  • 25
51
votes
8 answers

Fitting a Weibull distribution using Scipy

I am trying to recreate maximum likelihood distribution fitting, I can already do this in Matlab and R, but now I want to use scipy. In particular, I would like to estimate the Weibull distribution parameters for my data set. I have tried…
kungphil
  • 1,759
  • 2
  • 18
  • 27