scipy

scipy slow sparse matrix solver

99封情书 提交于 2021-01-29 05:50:39
问题 I can't seem to get a benefit out of scipy's CG and sparse matrix algorithms. When I try to solve this banded matrix equation import time import scipy.sparse.linalg as ssla import scipy.sparse as ss import numpy as np size = 3000 x = np.ones(size) A = ss.diags([1, -2, 1], [-1, 0, 1], shape=[size, size]).toarray() print 'cond. nr.:{}'.format(np.linalg.cond(A)) b = np.dot(A, x) start_time = time.clock() sol = np.linalg.solve(A, b) elapsed_time = time.clock() - start_time error = np.sum(np.abs

How to select some rows from sparse matrix then use them form a new sparse matrix

左心房为你撑大大i 提交于 2021-01-29 05:34:32
问题 I have a very large sparse matrix(100000 column and 100000 rows). I want to select some of the rows of this sparse matrix and then use them to form a new sparse matrix. I tried to do it by first converting them to dense matrix and then convert them to sparse matrix again. But when I do this python raise a 'Memory error'. Then I tried another method, which is I select the rows of sparse matrix and then put them into a array, but when I try to convert this array to sparse matrix, it says:

2 Dendrograms + Heatmap from condensed correlationmatrix with scipy

烈酒焚心 提交于 2021-01-29 05:23:03
问题 I try to create something like this: plotting results of hierarchical clustering ontop of a matrix of data in python Unfortunatelly when I try to execute the code, I get the following warnings: Warning (from warnings module): File "C:\Users\USER1\Desktop\test.py", line 15 Y = sch.linkage(D, method='centroid') ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix Warning (from warnings module): File "C:\Users

How to change support of multivariate integral to [0,1]^k using scipy.integrate.quad?

∥☆過路亽.° 提交于 2021-01-29 05:21:08
问题 The following k-dimension integral has dependent limits (a support dependent on gamma ): from scipy.integrate import nquad import numpy as np def func(*args): gamma = args[-1] var = np.array(args[:-1]) return (1-1/(1+gamma-np.sum(var)))*np.prod(((1+var)**-2)) def range_func(*args): gamma = args[-1] return (0, gamma-sum(args[:-1])) gamma, k = 10, 2 print(nquad(func, [range_func]*k, args=(gamma,) )) The limits are defined inside the function range_func above return (0, gamma-sum(args[:-1])) How

Scipy GridData QhullError: center point is coplanar with a facet, or a vertex is coplanar with a neighboring facet

十年热恋 提交于 2021-01-29 05:20:44
问题 I'm having a strange issue using scipy.interpolate.griddata . It's a QhullError . It says center point is coplanar with a facet, or a vertex is coplanar with a neighboring facet. . What does this error mean? How can it be overcome? from scipy.interpolate import griddata import numpy as np def f(x, y): return (1 - x) ** 2 * 10 * (y - x**2) ** 2 X = np.linspace(-3, 3) Y = np.linspace(-3, 3) Z = f(X, Y) xi = np.linspace(X.min(), X.max(), 1000) yi = np.linspace(Y.min(), Y.max(), 1000) zi =

Python scipy.optimise.curve_fit gives linear fit

…衆ロ難τιáo~ 提交于 2021-01-29 04:20:21
问题 I have come across a problem when playing with the parameters of the curve_fit from scipy. I have initially copied the code suggested by the docs. I then changed the equation slightly and it was fine, but having increased the np.linspace, the whole prediction ended up being a straight line. Any ideas? import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt def f(x, a, b, c): # This works fine on smaller numbers return (a - c) * np.exp(-x / b) + c xdata = np

scipy rv_continuous very slow

我只是一个虾纸丫 提交于 2021-01-29 04:01:27
问题 I am using a custom function f(x) to define a custom distribution using copy 's rv_continuous class. My code is class my_pdf_gen(rv_continuous): def _pdf(self, x, integral): return f(x)/integral where integral ensure the normalisation. I am able to create an instance of it with my_pdf = my_pdf_gen(my_int,a = a, b = b, name = 'my pdf') with a,b the upper and lower limit of the value's range, and my_int= scipy.integrate.quad(f, a, b)[0] . I am also able to create a random sample of data using

Python Audio fftpack: Filter noise signal and graph it?

强颜欢笑 提交于 2021-01-29 03:57:40
问题 So I'm follow a tutorial where we create a signal and filter the noise using fftpack. Problem 1: I'm trying to plot the filtered and unfiltered signal noise on a graph so that I can see them side by side. Getting error: Warning (from warnings module): File "C:\Python39\lib\site-packages\numpy\core_asarray.py", line 83 return array(a, dtype, copy=False, order=order) ComplexWarning: Casting complex values to real discards the imaginary part I think this is causing the error: y = sig x = time

SciPy curve_fit not working when one of the parameters to fit is a power

不打扰是莪最后的温柔 提交于 2021-01-29 03:31:03
问题 I'm trying to fit my data to a user defined function using SciPy curve_fit, which works when fitting to a function with a fixed power (func1). But curve_fit does not work when the function contains a power as a parameter to fit to (func2). Curve_fit still does not work if I provide an initial guess for the parameters usins the keyword p0 . I can not use the bounds keyword as the version of SciPy which I have does not have it. This script illustrates the point: import scipy from scipy.optimize

SciPy curve_fit not working when one of the parameters to fit is a power

牧云@^-^@ 提交于 2021-01-29 03:30:51
问题 I'm trying to fit my data to a user defined function using SciPy curve_fit, which works when fitting to a function with a fixed power (func1). But curve_fit does not work when the function contains a power as a parameter to fit to (func2). Curve_fit still does not work if I provide an initial guess for the parameters usins the keyword p0 . I can not use the bounds keyword as the version of SciPy which I have does not have it. This script illustrates the point: import scipy from scipy.optimize