scipy

scipy.interpolate problems with inputing values

我与影子孤独终老i 提交于 2021-01-29 17:42:42
问题 Currently trying to use scipy's implementation of interpolate to create a uniform cubic B-spline (clamped). When using interpolate.splev() the target (x) value I pass in is changed and the function returns me the x value of a point near but not the same as the target value (and the correct y value for the wrong x value). Anybody got any advice on how I can resolve this problem? Code provided below to recreate problem. Thank you very much in advance :) import numpy as np import random as rd

Is there a way to store intermediate values when using solve_ivp?

折月煮酒 提交于 2021-01-29 13:00:36
问题 I'm working on a system of differential equation that I solve with scipy.integrate.solve_ivp. For each variation term of this system I combine different intermediate variables. I'm looking for a way to store those intermediate variables and not only the resulting variables. I've thinking to use a list or some other kind of iterable to store the intermediate values directly in the func passed to solve_ivp but it doesn't seem to be the best approach and doesn't allow me to use the interpolants,

Different behaviour between MATLAB fmincon and scipy optimize minimize

我与影子孤独终老i 提交于 2021-01-29 12:30:54
问题 I'm translating some code from MATLAB to python. This code simulate the behaviour of a model and I want to estimate parameters from it. The problem is that results obtained with python and with MATLAB are very different. I've tought it was related to the difference between the MATLAB's fmincon and the python scipy.optimize.minimize function, but according to this tutorial that I've found on youtube (https://www.youtube.com/watch?v=SwogAa1719M) the results are almost the same,so problems must

Is there a way to store intermediate values when using solve_ivp?

陌路散爱 提交于 2021-01-29 12:15:38
问题 I'm working on a system of differential equation that I solve with scipy.integrate.solve_ivp. For each variation term of this system I combine different intermediate variables. I'm looking for a way to store those intermediate variables and not only the resulting variables. I've thinking to use a list or some other kind of iterable to store the intermediate values directly in the func passed to solve_ivp but it doesn't seem to be the best approach and doesn't allow me to use the interpolants,

Python: Integral and funcion nested in another integral using scipy quad

梦想的初衷 提交于 2021-01-29 09:40:28
问题 I have managed to write a few lines of code using scipy.integrate.quad for my stochastic process class I have the Markov transition function for standard Brownian motion import numpy as np def p(x,t): return (1/np.sqrt(2*np.pi*t))*np.exp(-x**2/(2*t)) But I want to compute the following that I am going to write in code that would not work. I write it like this so we can understand the problem without the use of latex. from scipy.integrate import quad integral = quad(quad(p(y-x),1,np.inf)*p(x,1

scipy import error with pyinstaller

旧巷老猫 提交于 2021-01-29 08:42:54
问题 I am trying to build a "One File" executable for my project with pyinstaller and a .spec file. The content of the spec file is as follows: # -*- mode: python -*- block_cipher = None a = Analysis(['__main__.py'], pathex=['D:\\opt_frame'], binaries=[], datas=[], hiddenimports=['scipy.special', 'scipy.special.comb'], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

How to simulate one step to a transfer function in python

怎甘沉沦 提交于 2021-01-29 08:28:28
问题 I've found scipy.signal.dstep , scipy.signal.dlsim functions that help simulate behavior of a transfer function, for example: signal.dlsim(signal.cont2discrete(([1], [1, 1]), 0.1), u=[1, 1], t=[0.0, 0.1]) allows to model 1/(s+1) function in [0, 0.1] time interval with control signal with value 1 . But these functions do not allow to model just one step with initial values. Are there any other functions that allow to model one step of a transfer function or how it's better to do it? 回答1: First

How to get a sigmodal CDF curve use scipy.stats.norm.cdf and matplotlib?

孤者浪人 提交于 2021-01-29 06:32:28
问题 I am trying to plot the S-shape cumulative distribution function (cdf) curve of a normal distribution. However, I ended up with a uniform distribution. What am I doing wrong? Test Script import numpy as np from numpy.random import default_rng from scipy.stats import norm import matplotlib.pyplot as plt siz = 1000 rg = default_rng( 12345 ) a = rg.random(size=siz) rg = default_rng( 12345 ) b = norm.rvs(size=siz, random_state=rg) c = norm.cdf(b) print( 'a = ', a) print( 'b = ', b) print( 'c = ',

How to efficiently split scipy sparse and numpy arrays into smaller N unequal chunks?

隐身守侯 提交于 2021-01-29 06:01:16
问题 After checking the documentation and this question I tried to split a numpy array and a sparse scipy matrices as follows: >>>print(X.shape) (2399, 39999) >>>print(type(X)) <class 'scipy.sparse.csr.csr_matrix'> >>>print(X.toarray()) [[0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0] ..., [0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0]] Then: new_array = np.split(X,3) Out: ValueError: array split does not result in an equal division Then I tried to: new_array = np.hsplit(X,3)

scipy slow sparse matrix solver

不问归期 提交于 2021-01-29 05:52:31
问题 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