scipy

Generating equidistance points along the boundary of a polygon but CW/CCW

房东的猫 提交于 2021-02-08 06:15:36
问题 Suppose I have the vertices of a polygon and they are all oriented CCW. I wish to generate n equidistance points along the boundary of this polygon. Does anyone know of any existing package that does this, and if not, an algorithm one can use? I am working in Python. For example, here is what I would like if the polygon in question is a rectangle: enter image description here 回答1: shapely : import shapely.geometry as sg import shapely.affinity as sa import matplotlib.pyplot as P import numpy

Generating equidistance points along the boundary of a polygon but CW/CCW

╄→гoц情女王★ 提交于 2021-02-08 06:15:32
问题 Suppose I have the vertices of a polygon and they are all oriented CCW. I wish to generate n equidistance points along the boundary of this polygon. Does anyone know of any existing package that does this, and if not, an algorithm one can use? I am working in Python. For example, here is what I would like if the polygon in question is a rectangle: enter image description here 回答1: shapely : import shapely.geometry as sg import shapely.affinity as sa import matplotlib.pyplot as P import numpy

Generating equidistance points along the boundary of a polygon but CW/CCW

ε祈祈猫儿з 提交于 2021-02-08 06:15:08
问题 Suppose I have the vertices of a polygon and they are all oriented CCW. I wish to generate n equidistance points along the boundary of this polygon. Does anyone know of any existing package that does this, and if not, an algorithm one can use? I am working in Python. For example, here is what I would like if the polygon in question is a rectangle: enter image description here 回答1: shapely : import shapely.geometry as sg import shapely.affinity as sa import matplotlib.pyplot as P import numpy

how to add error bars to histogram diagram in python

这一生的挚爱 提交于 2021-02-08 05:33:42
问题 Hi I want to add error bars to the histogram within this code.I have seen few post about it but I didn't find them helpful.this code produce random numbers with Gaussian distribution and a kernel estimation apply to it.I need to have errorbars to estimate how much the histogram is inaccurate with changing the bandwidth from random import * import numpy as np from matplotlib.pyplot import* from matplotlib import* import scipy.stats as stats def hist_with_kde(data, bandwidth = 0.3): #set number

retrieve leave colors from scipy dendrogram

南楼画角 提交于 2021-02-08 05:17:35
问题 I can not get the color leaves from the scipy dendrogram dictionary. As stated in the documentation and in this github issue, the color_list key in the dendrogram dictionary refers to the links, not the leaves. It would be nice to have another key referring to the leaves, sometimes you need this for coloring other types of graphics, such as this scatter plot in the example below. import numpy as np import matplotlib.pyplot as plt from scipy.cluster.hierarchy import linkage, dendrogram # DATA

Scipy cosine similarity vs sklearn cosine similarity

ⅰ亾dé卋堺 提交于 2021-02-08 04:30:28
问题 I noticed that both scipy and sklearn have a cosine similarity/cosine distance functions. I wanted to test the speed for each on pairs of vectors: setup1 = "import numpy as np; arrs1 = [np.random.rand(400) for _ in range(60)];arrs2 = [np.random.rand(400) for _ in range(60)]" setup2 = "import numpy as np; arrs1 = [np.random.rand(400) for _ in range(60)];arrs2 = [np.random.rand(400) for _ in range(60)]" import1 = "from sklearn.metrics.pairwise import cosine_similarity" stmt1 = "[float(cosine

Gaussian fit returning negative sigma

狂风中的少年 提交于 2021-02-07 20:20:39
问题 One of my algorithms performs automatic peak detection based on a Gaussian function, and then later determines the the edges based either on a multiplier (user setting) of the sigma or the 'full width at half maximum'. In the scenario where a user specified that he/she wants the peak limited at 2 Sigma, the algorithm takes -/+ 2*sigma from the peak center (mu). However, I noticed that the sigma returned by curve_fit can be negative, which is something that has been noticed before as can be

Marginalize a surface plot and use kernel density estimation (kde) on it

爷,独闯天下 提交于 2021-02-07 20:01:23
问题 As a minimal reproducible example, suppose I have the following multivariate normal distribution: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from scipy.stats import multivariate_normal, gaussian_kde # Choose mean vector and variance-covariance matrix mu = np.array([0, 0]) sigma = np.array([[2, 0], [0, 3]]) # Create surface plot data x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) rv = multivariate_normal(mean=mu,

Marginalize a surface plot and use kernel density estimation (kde) on it

偶尔善良 提交于 2021-02-07 20:01:12
问题 As a minimal reproducible example, suppose I have the following multivariate normal distribution: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from scipy.stats import multivariate_normal, gaussian_kde # Choose mean vector and variance-covariance matrix mu = np.array([0, 0]) sigma = np.array([[2, 0], [0, 3]]) # Create surface plot data x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) rv = multivariate_normal(mean=mu,

Marginalize a surface plot and use kernel density estimation (kde) on it

不问归期 提交于 2021-02-07 20:00:24
问题 As a minimal reproducible example, suppose I have the following multivariate normal distribution: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from scipy.stats import multivariate_normal, gaussian_kde # Choose mean vector and variance-covariance matrix mu = np.array([0, 0]) sigma = np.array([[2, 0], [0, 3]]) # Create surface plot data x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) rv = multivariate_normal(mean=mu,