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

What is the difference between numpy.linalg.lstsq and scipy.linalg.lstsq?

lstsq tries to solve Ax=b minimizing |b - Ax|. Both scipy and numpy provide a linalg.lstsq function with a very similar interface. The documentation does not mention which kind of algorithm is used, neither for scipy.linalg.lstsq nor for…
lumbric
  • 7,644
  • 7
  • 42
  • 53
39
votes
4 answers

how to explain the decision tree from scikit-learn

I have two problems with understanding the result of decision tree from scikit-learn. For example, this is one of my decision trees: My question is that how I can use the tree? The first question is that: if a sample satisfied the condition, then…
Student Jack
  • 1,025
  • 2
  • 14
  • 19
39
votes
7 answers

Random Number from Histogram

Suppose I create a histogram using scipy/numpy, so I have two arrays: one for the bin counts, and one for the bin edges. If I use the histogram to represent a probability distribution function, how can I efficiently generate random numbers from that…
xvtk
  • 1,030
  • 2
  • 10
  • 18
39
votes
7 answers

How to create a white image in Python?

Upon doing my homework, I stumbled across a problem concerning Python and image manipulation. I must say, using the Image lib is not an option. So here it is from scipy.misc import imread,imsave from numpy import zeros imga = zeros([100,100,3]) h =…
Lefix
  • 575
  • 1
  • 5
  • 14
38
votes
4 answers

correct and efficient way to flatten array in numpy in python?

I have: a = array([[1,2,3],[4,5,6]]) and I'd like to flatten it, joining the two inner lists into one flat array entry. I can do: array(list(flatten(a))) but that seems inefficient due to the list cast (I want to end up with an array and not a…
user248237
38
votes
5 answers

scipy, lognormal distribution - parameters

I want to fit lognormal distribution to my data, using python scipy.stats.lognormal.fit. According to the manual, fit returns shape, loc, scale parameters. But, lognormal distribution normally needs only two parameters: mean and standard…
Jakub M.
  • 32,471
  • 48
  • 110
  • 179
38
votes
6 answers

Python (NumPy, SciPy), finding the null space of a matrix

I'm trying to find the null space (solution space of Ax=0) of a given matrix. I've found two examples, but I can't seem to get either to work. Moreover, I can't understand what they're doing to get there, so I can't debug. I'm hoping someone might…
Nona Urbiz
  • 4,873
  • 16
  • 57
  • 84
38
votes
2 answers

Fit sigmoid function ("S" shape curve) to data using Python

I'm trying to fit a sigmoid function to some data I have but I keep getting:ValueError: Unable to determine number of fit parameters. My data looks like this: My code is: from scipy.optimize import curve_fit def sigmoid(x): return…
user88484
  • 1,249
  • 1
  • 13
  • 34
38
votes
2 answers

`ValueError: A value in x_new is above the interpolation range.` - what other reasons than not ascending values?

I receive this error in scipy interp1d function. Normally, this error would be generated if the x was not monotonically increasing. import scipy.interpolate as spi def refine(coarsex,coarsey,step): finex =…
durbachit
  • 4,626
  • 10
  • 36
  • 49
38
votes
5 answers

Plot a plane based on a normal vector and a point in Matlab or matplotlib

How would one go plotting a plane in matlab or matplotlib from a normal vector and a point?
Xzhsh
  • 2,239
  • 2
  • 22
  • 32
38
votes
7 answers

Get U, Sigma, V* matrix from Truncated SVD in scikit-learn

I am using truncated SVD from scikit-learn package. In the definition of SVD, an original matrix A is approxmated as a product A ≈ UΣV* where U and V have orthonormal columns, and Σ is non-negative diagonal. I need to get the U, Σ and V* matrices.…
Vektor88
  • 4,841
  • 11
  • 59
  • 111
38
votes
1 answer

ANOVA in python using pandas dataframe with statsmodels or scipy?

I want to use the Pandas dataframe to breakdown the variance in one variable. For example, if I have a column called 'Degrees', and I have this indexed for various dates, cities, and night vs. day, I want to find out what fraction of the variation…
wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
38
votes
2 answers

scipy minimize with constraints

Let's suppose I have a matrix arr = array([[0.8, 0.2],[-0.1, 0.14]]) with a target function def matr_t(t): return array([[t[0], 0],[t[2]+complex(0,1)*t[3], t[1]]] def target(t): arr2 = matr_t(t) ret = 0 for i, v1 in…
wa4557
  • 953
  • 3
  • 13
  • 25
38
votes
4 answers

My scipy.misc module appears to be missing imsave

I open the python3 interpreter and type import scipy.misc scipy.misc.imsave with the result Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'imsave' Has the name changed? It…
Cramer
  • 1,785
  • 1
  • 12
  • 20
38
votes
5 answers

How to interpret the values returned by numpy.correlate and numpy.corrcoef?

I have two 1D arrays and I want to see their inter-relationships. What procedure should I use in numpy? I am using numpy.corrcoef(arrayA, arrayB) and numpy.correlate(arrayA, arrayB) and both are giving some results that I am not able to comprehend…
khan
  • 7,005
  • 15
  • 48
  • 70