scipy

Different results when computing integral analytically/with scipy VS approximating integral

Different results when computing integral analytically/with scipy VS approximating integral Question: I’m trying to calculate the integral of a variant of the Hill Equation shown here. When I try implementing this with the integrate function in SciPy, I get the following: from scipy import integrate Top = 0.9015038230670139 Bottom = 0.5972679490151096 ic50 = 17561.998143066336 Coef …

Total answers: 1

failed to hear audio on jupyter with librosa but can with scipy – sampling rate issues?

failed to hear audio on jupyter with librosa but can with scipy – sampling rate issues? Question: I can hear audio in jupyter if loaded with scipy. However, I can hear untill 192000 sampling rate. If I set to 192001 or above, I cannot hear anything. from IPython.display import Audio from scipy.io.wavfile import read wave_filename …

Total answers: 1

scipys quadrature function complains about perfectly sane lambda?

scipys quadrature function complains about perfectly sane lambda? Question: I have 2 versions of a snippet one works one doesn’t, this works: f = lambda x : x * 2.0 * pi print(scipy.integrate.quadrature(f, 0.0, 1.0)) This fails: f = lambda x : math.exp(x * 2.0 * pi)` print(scipy.integrate.quadrature(f, 0.0, 1.0)) With error: TypeError: only size-1 …

Total answers: 1

How to build an expanding mathematical expression in Python?

How to build an expanding mathematical expression in Python? Question: I have a problem where I need to solve a polynomial of a degree that increases with each iteration (loop). The expression is (1/(1+x)^1) + (1/(1+x)^2) + (1/(1+x)^3) + (1/(1+x)^4) + (1/(1+x)^5) As you can see, the exponential grows with each iteration and this expression …

Total answers: 4

Curve.fit optimization error: 'Covariance of the parameters could not be estimated

Curve.fit optimization error: 'Covariance of the parameters could not be estimated Question: I’m trying to fit some data into a function, but scipy curve_fit gives me the following message: "OptimizeWarning: Covariance of the parameters could not be estimated" and won’t plot or print the parameters of the fit. I believe the power inside the exp …

Total answers: 1

SciPy's Fisher's Exact P-Value Differs from Exact Formula

SciPy's Fisher's Exact P-Value Differs from Exact Formula Question: I recently computed Fisher’s Exact Test for a 2×2 contingency table using SciPy’s built in fisher_exact() function. I’m using their example code from the SciPy docs: >>> from scipy.stats import fisher_exact >>> import numpy as np >>> table = np.array([[6, 2], [1, 4]]) >>> res = …

Total answers: 1

Why can't I pass a decorated function to scipy.integrate.ode?

Why can't I pass a decorated function to scipy.integrate.ode? Question: When I pass a decorated function to scipy.integrate.ode, the wrapper function gets called, but *args is empty. Why is this happening? This works: y0, t0 = 1, 0 def dydt(t, y): return y*0.5 r = scipy.integrate.ode(dydt) r.set_initial_value(y0) r.integrate(10) assert r.successful() This doesn’t: y0, t0 = …

Total answers: 2

Fastest way to find nearest neighbours in NumPy array

Fastest way to find nearest neighbours in NumPy array Question: What is the fastest way to perform operations on adjacent elements of an mxn array within distance $l$ (where m, n are large). If this was an image, it would equate to an operation on the surrounding pixels. To make things clearer, I’ve created a …

Total answers: 1

Maintaining Sharp Corners in a Numpy Interpolation

Maintaining Sharp Corners in a Numpy Interpolation Question: I am interpolating a shape with numpy’s linspace and interp using gboffi‘s magnificent code from this post (included, below). This works well, however, the corners sometimes get missed and the resulting softened shape is undesired. I’d like to maintain the sharp corners of my shapes with an …

Total answers: 4