scipy

Create BSpline from knots and coefficients

半世苍凉 提交于 2021-01-27 19:20:23
问题 How can a spline be created if only the points and the coefficients are known? I'm using scipy.interpolate.BSpline here, but am open to other standard packages as well. So basically I want to be able to give someone just those short arrays of coefficients for them to be able to recreate the fit to the data. See the failed red-dashed curve below. import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import BSpline, LSQUnivariateSpline x = np.linspace(0, 10, 50) # x-data y =

Fit differential equation with scipy

不问归期 提交于 2021-01-27 18:37:29
问题 how can I fit the differential function of the followint scipy tutorial Scipy Differential Equation Tutorial? In the end I want to fit some datapoints that follow a set of two differential equations with six parameters in total but I'd like to start with an easy example. So far I tried the functions scipy.optimize.curve_fit and scipy.optimize.leastsq but I did not get anywhere. So this is how far I came: import numpy as np import scipy.optimize as scopt import scipy.integrate as scint import

Create BSpline from knots and coefficients

不想你离开。 提交于 2021-01-27 18:14:39
问题 How can a spline be created if only the points and the coefficients are known? I'm using scipy.interpolate.BSpline here, but am open to other standard packages as well. So basically I want to be able to give someone just those short arrays of coefficients for them to be able to recreate the fit to the data. See the failed red-dashed curve below. import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import BSpline, LSQUnivariateSpline x = np.linspace(0, 10, 50) # x-data y =

Initialize high dimensional sparse matrix

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 13:22:59
问题 I want to initialize 300,000 x 300,0000 sparse matrix using sklearn , but it requires memory as if it was not sparse: >>> from scipy import sparse >>> sparse.rand(300000,300000,.1) it gives the error: MemoryError: Unable to allocate 671. GiB for an array with shape (300000, 300000) and data type float64 which is the same error as if I initialize using numpy : np.random.normal(size=[300000, 300000]) Even when I go to a very low density, it reproduces the error: >>> from scipy import sparse >>>

Saving dictionaries from Python to Matlab with Scipy

孤人 提交于 2021-01-27 13:06:02
问题 I'm finding some problems to save my neat generated data into .mat files. I thought it was more straightforward with Scipy, but it seems I'm getting something wrong. This is an example of data I want to save: out = {'features': array([[ 5.00088905e+01, 1.51847522e+01, 4.93513862e+01, 3.76548415e+00, -3.96946513e+01, -2.11885850e+01, 9.85304035e+00, -6.30005764e+00, 1.19987435e+01, 3.89762536e+00, -1.31554755e+00, -1.66890836e+01, 4.75289017e-02, 3.65829480e-01, -4.77872832e-01, 1.13641908e+00

Trying to fit a trig function to data with scipy

杀马特。学长 韩版系。学妹 提交于 2021-01-27 13:04:39
问题 I am trying to fit some data using scipy.optimize.curve_fit . I have read the documentation and also this StackOverflow post, but neither seem to answer my question. I have some data which is simple, 2D data which looks approximately like a trig function. I want to fit it with a general trig function using scipy . My approach is as follows: from __future__ import division import numpy as np from scipy.optimize import curve_fit #Load the data data = np.loadtxt('example_data.txt') t = data[:,0]

Trying to fit a trig function to data with scipy

人盡茶涼 提交于 2021-01-27 13:00:55
问题 I am trying to fit some data using scipy.optimize.curve_fit . I have read the documentation and also this StackOverflow post, but neither seem to answer my question. I have some data which is simple, 2D data which looks approximately like a trig function. I want to fit it with a general trig function using scipy . My approach is as follows: from __future__ import division import numpy as np from scipy.optimize import curve_fit #Load the data data = np.loadtxt('example_data.txt') t = data[:,0]

python log n choose k

我的未来我决定 提交于 2021-01-27 12:29:17
问题 scipy.misc.comb, returning n choose k, is implemented using the gammaln function. Is there a function that stays in log space? I see there is no scipy.misc.combln or any similar. It is trivial to implement myself, but it would be convenient if it were already in a package somewhere. I don't see it in scipy.misc, and it just feels wasteful to convert to normal space and then back to log. 回答1: Looking at the source code, it seems like you're right that it would be trivial to implement, but that

overflow error Plot

假装没事ソ 提交于 2021-01-27 12:15:51
问题 I want do stuff with sound/ audio and music processing. Before this i created a sample signal with a 10 second sweep. I have a simple script which have to plot some signals. First signal is a simple sine; second a sweep; Both with frequency just below Nyquist frequency so thats no problem. The Code: #import import numpy as np import scipy.signal as sig import matplotlib.pylab as plt f0 = 50 f1 = 20000 t1 = 10 t = np.arange(0,t1,1/44100)#[numpy.newaxis]; print(t.shape) sine = np.sin(2*np.pi*f0

Multivariate Root Finding in Python

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-27 07:58:37
问题 Using excel solver, it is easy to find a solution (optimum value for x and y )for this equation: (x*14.80461) + (y * -4.9233) + (10*0.4803) ≈ 0 However, I can't figure out how to do this in Python. The existing scipy optimize library function like fsolve() or leastsq() seems to work with only one variable.... (I might just not know how to use them)... Any suggestions? Thanks! 回答1: >>> def f(x): ... return x[0]*14.80461 + x[1]*(-4.9233) + x[2]*(10*0.4803) >>> def vf(x): ... return [f(x), 0, 0]