scipy

python scipy.signal.peak_widths --> absolute heigth? (fft -3dB damping)

a 夏天 提交于 2021-02-19 05:29:46
问题 https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak_widths.html I think the linked function can only calculate the peak widths at a relative height. Does anyone know if there is a function that calculates the width at a fixed value (peak_amplitude - x) for all peaks? Currently I am trying to change the original inner function "_peak_widths". Fail already with the cimport. Understand the source code here only partially. I added in the code where I would make a modification.

Is it possible to enforce edges (constrained delaunay triangulation) in scipy.spatial's Delaunay?

点点圈 提交于 2021-02-19 04:52:05
问题 I am experimenting with scipy.spatial's implementation of Qhull's Delaunay triangulation. Is it possible to generate the triangulation in a manner that preserves the edges defined by the input vertices? (EDIT: i.e. a constrained Delaunay triangulation.) As can be done with the triangle package for Python. For example, in the picture below there are several triangles (blue) that disregard the location of the edges (red) that are defined by the vertices. Is there a way to enforce these edges

L1 convex optimization with equality constraints in python

隐身守侯 提交于 2021-02-19 04:48:30
问题 I need to minimize L_1(x) subject to Mx = y. x is a vector with dimension b, y is a vector with dimension a, and M is a matrix with dimensions (a,b). After some reading I determined to use scipy.optimize.minimize: import numpy as np from scipy.optimize import minimize def objective(x): #L_1 norm objective function return np.linalg.norm(x,ord=1) constraints = [] #list of all constraint functions for i in range(a): def con(x,y=y,i=i): return np.matmul(M[i],x)-y[i] constraints.append(con) #make

How to understand the pivot matrix of scipy.linalg.lu_factor?

时光怂恿深爱的人放手 提交于 2021-02-19 02:58:12
问题 How can I manually reconstruct a matrix A that was factorized by lu_factor? ( A = PLU ) My current attempts all failed due to the setup of matrix P . Here is what I have so far: A = np.random.rand(3,3) lu, piv = lu_factor(A) U = np.triu(lu) L = np.tril(lu, -1) L[np.diag_indices_from(L)] = 1.0 I am looking for the matrix P that makes this line print True : print np.allclose(A, np.dot(P, np.dot(L, U))) Any hint/link/suggestion is appreciated! 回答1: The permutation vector needs to be interpreted

Matplotlib - set pad between arrow and text in annotate function

若如初见. 提交于 2021-02-19 01:34:34
问题 How do I set the distance (padding) between the arrow and the text in matplotlib's annotate function? Sometimes the text ends up being too close to the arrow and I would like to move them a little further apart. Basic example: import matplotlib.pyplot as plt plt.annotate('Here it is!',xy=(-1,-1),xytext=(0,0), arrowprops=dict(arrowstyle='->',lw=1.5)) plt.xlim(-10,10) plt.ylim(-10,10) plt.show() 回答1: For fancy arrows you can play with the bbox properties: fig, ax = plt.subplots(1, 3, figsize=(7

Matplotlib - set pad between arrow and text in annotate function

江枫思渺然 提交于 2021-02-19 01:33:55
问题 How do I set the distance (padding) between the arrow and the text in matplotlib's annotate function? Sometimes the text ends up being too close to the arrow and I would like to move them a little further apart. Basic example: import matplotlib.pyplot as plt plt.annotate('Here it is!',xy=(-1,-1),xytext=(0,0), arrowprops=dict(arrowstyle='->',lw=1.5)) plt.xlim(-10,10) plt.ylim(-10,10) plt.show() 回答1: For fancy arrows you can play with the bbox properties: fig, ax = plt.subplots(1, 3, figsize=(7

How do I “randomly” select numbers with a specified bias toward a particular number

蓝咒 提交于 2021-02-19 00:42:10
问题 How do I generate random numbers with a specified bias toward one number. For example, how would I pick between two numbers, 1 and 2, with a 90% bias toward 1. The best I can come up with is... import random print random.choice([1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) Is there a better way to do this? The method I showed works in simple examples but eventually I'll have to do more complicated selections with biases that are very specific (such as 37.65% bias) which would require a very long list. EDIT

How do I “randomly” select numbers with a specified bias toward a particular number

旧城冷巷雨未停 提交于 2021-02-19 00:39:47
问题 How do I generate random numbers with a specified bias toward one number. For example, how would I pick between two numbers, 1 and 2, with a 90% bias toward 1. The best I can come up with is... import random print random.choice([1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) Is there a better way to do this? The method I showed works in simple examples but eventually I'll have to do more complicated selections with biases that are very specific (such as 37.65% bias) which would require a very long list. EDIT

what is the meaning of the return values of the scipy.cluster.hierarchy.linkage?

安稳与你 提交于 2021-02-18 13:50:56
问题 Let assume that we have X matrix as follows: [[9 0] [1 4] [2 3] [8 5]] Then, from scipy.cluster.hierarchy import linkage Z = linkage(X, method="ward") print(Z) The returning matrix is follows: [[ 1. 2. 1.41421356 2. ] [ 0. 3. 5.09901951 2. ] [ 4. 5. 10. 4. ]] What is the meaning of the returning values? 回答1: Although this has been answered before, it was a "read the docs" answer. I think it is useful to explain the docs a bit. From the docs, we read that: An (n−1) by 4 matrix Z is returned.

what is the meaning of the return values of the scipy.cluster.hierarchy.linkage?

限于喜欢 提交于 2021-02-18 13:50:07
问题 Let assume that we have X matrix as follows: [[9 0] [1 4] [2 3] [8 5]] Then, from scipy.cluster.hierarchy import linkage Z = linkage(X, method="ward") print(Z) The returning matrix is follows: [[ 1. 2. 1.41421356 2. ] [ 0. 3. 5.09901951 2. ] [ 4. 5. 10. 4. ]] What is the meaning of the returning values? 回答1: Although this has been answered before, it was a "read the docs" answer. I think it is useful to explain the docs a bit. From the docs, we read that: An (n−1) by 4 matrix Z is returned.