scipy

1D Wasserstein distance in Python

十年热恋 提交于 2020-12-13 05:23:13
问题 The formula below is a special case of the Wasserstein distance/optimal transport when the source and target distributions, x and y (also called marginal distributions) are 1D, that is, are vectors. where F^{-1} are inverse probability distribution functions of the cumulative distributions of the marginals u and v , derived from real data called x and y , both generated from the normal distribution: import numpy as np from numpy.random import randn import scipy.stats as ss n = 100 x = randn(n

How to fit a non linear function with python?

爷,独闯天下 提交于 2020-12-13 04:33:45
问题 I have the following code written in R to estimate three coefficients (a, b and c): y <- c(120, 125, 158, 300, 350, 390, 2800, 5900, 7790) t <- 1:9 fit <- nls(y ~ a * (((b + c)^2/b) * exp(-(b + c) * t))/(1 + (c/b) * exp(-(b + c) * t))^2, start = list(a = 17933, b = 0.01, c = 0.31)) and i get this result > summary(fit ) Formula: y ~ a * (((b + c)^2/b) * exp(-(b + c) * t))/(1 + (c/b) * exp(-(b + c) * t))^2 Parameters: Estimate Std. Error t value Pr(>|t|) a 2.501e+04 2.031e+03 12.312 1.75e-05 **

Understanding `leafsize` in scipy.spatial.KDTree

自闭症网瘾萝莉.ら 提交于 2020-12-13 03:38:16
问题 Problem statement: I have 150k points in a 3D space with their coordinates stored in a matrix with dimension [150k, 3] in mm. I want to find all the neighbors of a given point p that are within a radius r . And I want to do that in the most accurate way. How should I choose my leafsize parameter ? from scipy.spatial import KDTree import numpy as np pts = np.random.rand(150000,3) T1 = KDTree(pts, leafsize=20) T2 = KDTree(pts, leafsize=1) neighbors1= T1.query_ball_point((0.3,0.2,0.1), r=2.0)

Understanding `leafsize` in scipy.spatial.KDTree

一笑奈何 提交于 2020-12-13 03:34:11
问题 Problem statement: I have 150k points in a 3D space with their coordinates stored in a matrix with dimension [150k, 3] in mm. I want to find all the neighbors of a given point p that are within a radius r . And I want to do that in the most accurate way. How should I choose my leafsize parameter ? from scipy.spatial import KDTree import numpy as np pts = np.random.rand(150000,3) T1 = KDTree(pts, leafsize=20) T2 = KDTree(pts, leafsize=1) neighbors1= T1.query_ball_point((0.3,0.2,0.1), r=2.0)

Python - Integrating a function and plotting results

我们两清 提交于 2020-12-13 03:21:30
问题 I'm trying to solve Bernoulli's beam equation numerically and plotting the results. First derivative of the equation is the slope and the second derivative is the deflection. I approached the problem step-by-step, first plot the function and then integrate it and plot the integration results on the same diagram. My code so far is bellow. I suspect the problem lies in the fact that the integrate.quad returns a single value and I'm trying to get multiple values from it. Does anyone know how to

How to fit the best probability distribution model to my data in python?

点点圈 提交于 2020-12-12 05:33:40
问题 i have about 20,000 rows of data like this,, Id | value 1 30 2 3 3 22 .. n 27 I did statistics to my data,, the average value 33.85, median 30.99, min 2.8, max 206, 95% confidence interval 0.21.. So most values around 33, and there are some outliers (a little).. So it seems like a distribution with long tail. I am new to both distribution and python,, i tried class fitter https://pypi.org/project/fitter/ to try many distribution from Scipy package,, and loglaplace distribution showed the

How to fit the best probability distribution model to my data in python?

人走茶凉 提交于 2020-12-12 05:31:09
问题 i have about 20,000 rows of data like this,, Id | value 1 30 2 3 3 22 .. n 27 I did statistics to my data,, the average value 33.85, median 30.99, min 2.8, max 206, 95% confidence interval 0.21.. So most values around 33, and there are some outliers (a little).. So it seems like a distribution with long tail. I am new to both distribution and python,, i tried class fitter https://pypi.org/project/fitter/ to try many distribution from Scipy package,, and loglaplace distribution showed the

How to fit the best probability distribution model to my data in python?

耗尽温柔 提交于 2020-12-12 05:30:15
问题 i have about 20,000 rows of data like this,, Id | value 1 30 2 3 3 22 .. n 27 I did statistics to my data,, the average value 33.85, median 30.99, min 2.8, max 206, 95% confidence interval 0.21.. So most values around 33, and there are some outliers (a little).. So it seems like a distribution with long tail. I am new to both distribution and python,, i tried class fitter https://pypi.org/project/fitter/ to try many distribution from Scipy package,, and loglaplace distribution showed the

Python实现音乐的剪辑

ⅰ亾dé卋堺 提交于 2020-12-12 01:44:47
一、读取音频文件 from scipy.io import wavfile import numpy as np like = wavfile.read( ' ./嘤嘤嘤.wav ' ) print (like)   结果:     图片是三维的ndarray,视频是四维的由[[img],[img],[img]]+音频组成    这里读取音频文件使用的scipy,scipy四个高端科学计算端。    音频结果将返回一个tuple。第一维参数是采样频率,单位为秒;第二维数据是一个ndarray表示歌曲,如果第二维的ndarray只有一个数据表示单声道,两个数据表示立体声。很明显这里是个立体声。   所以,通过控制第二维数据就能对歌曲进行裁剪。    继续音频裁剪就是:     like[1][ start_s*44100 : end_s*44100 ]     对like这个元组第二维数据进行裁剪,所以是like[1];第二维数据中是对音乐数据切分。 start_s表示你想裁剪音频的起始时间;同理end_s表示你裁剪音频的结束时间。乘44100 是因为每秒需要进行44100次采样。   对音频进行裁剪,并保存到本地,使用wavfile中的write: wavfile.write( ' like2.wav ' ,44100,like[1][30*44100:45*44100])  

Python安装cvxpy包的解决方案

浪尽此生 提交于 2020-12-08 07:44:57
背景 工作需要用到cvxpy库求解线性规划问题(cvxpy是解决凸优化问题的),发现安装不了,找了很多教程,发现都不是很靠谱,还把我自己的scipy包搞崩溃,很多之前的from scipy import stats这类都出错。现在把我成功安装的经验分享一下。 现象 安装cvxpy过程中需要scs等包,不会安装成功,你再去安装csc等包时会报没有Microsoft Visual C++ 14.0 (或者C++Build等错误 )。 解决办法: 1、 下载 安装C++或者组件后再安装cvxpy相关包。 (我本人是WIN7没有安装成功) 2、下载第三方python包 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载cvxpy相关的包(scs、cvxopt、ecos、multiprocess、scipy、cvxpy)到本地安装 # 在命令行输入下面命令 XXX为相应包名(连带后缀) pip install xxx . whl (我本人在安装scipy时把原来的搞崩溃了。 import scipy.stats 时的各种无法导入库(模块) 3、个人解决办法: 按照 scipy、cvxopt、scs、ecos、multiprocess、cvxpy 顺序依次(顺序错了可能会导致安装不成功)安装。 先 在线 安装 pip install ***