numpy

Curve fit an exponential decay function in Python using given data points

℡╲_俬逩灬. 提交于 2021-02-07 19:19:26
问题 With the curve_fit function in SciPy I'm able to determine the coefficients that represent the curve shown in the plot below. def func2(t, tau): return np.exp(-t / tau) t2 = np.linspace(0, 4, 50) y2 = func2(t2, 1.2) y2_noise = 0.2 * np.random.normal(size=t2.size) y2_curve_noise = y2 + y2_noise popt2, pcov2 = curve_fit(func2, t2, y2_curve_noise) tau2, = popt2 y2_fit = func2(t2, tau2) I would like to use a similar function to represent some data points. However, I'm unable to use this approach

Curve fit an exponential decay function in Python using given data points

我的未来我决定 提交于 2021-02-07 19:17:56
问题 With the curve_fit function in SciPy I'm able to determine the coefficients that represent the curve shown in the plot below. def func2(t, tau): return np.exp(-t / tau) t2 = np.linspace(0, 4, 50) y2 = func2(t2, 1.2) y2_noise = 0.2 * np.random.normal(size=t2.size) y2_curve_noise = y2 + y2_noise popt2, pcov2 = curve_fit(func2, t2, y2_curve_noise) tau2, = popt2 y2_fit = func2(t2, tau2) I would like to use a similar function to represent some data points. However, I'm unable to use this approach

How to convert RGB image to one-hot encoded 3d array based on color using numpy?

二次信任 提交于 2021-02-07 19:17:54
问题 Simply put, what I'm trying to do is similar to this question: Convert RGB image to index image, but instead of 1-channel index image, I want to get n-channel image where img[h, w] is a one-hot encoded vector. For example, if the input image is [[[0, 0, 0], [255, 255, 255]] , and index 0 is assigned to black and 1 is assigned to white, then the desired output is [[[1, 0], [0, 1]]] . Like the previous person asked the question, I have implemented this naively, but the code runs quite slowly,

How to convert RGB image to one-hot encoded 3d array based on color using numpy?

佐手、 提交于 2021-02-07 19:17:45
问题 Simply put, what I'm trying to do is similar to this question: Convert RGB image to index image, but instead of 1-channel index image, I want to get n-channel image where img[h, w] is a one-hot encoded vector. For example, if the input image is [[[0, 0, 0], [255, 255, 255]] , and index 0 is assigned to black and 1 is assigned to white, then the desired output is [[[1, 0], [0, 1]]] . Like the previous person asked the question, I have implemented this naively, but the code runs quite slowly,

How to convert RGB image to one-hot encoded 3d array based on color using numpy?

眉间皱痕 提交于 2021-02-07 19:17:09
问题 Simply put, what I'm trying to do is similar to this question: Convert RGB image to index image, but instead of 1-channel index image, I want to get n-channel image where img[h, w] is a one-hot encoded vector. For example, if the input image is [[[0, 0, 0], [255, 255, 255]] , and index 0 is assigned to black and 1 is assigned to white, then the desired output is [[[1, 0], [0, 1]]] . Like the previous person asked the question, I have implemented this naively, but the code runs quite slowly,

How to efficiently extract values from nested numpy arrays generated by loadmat function?

为君一笑 提交于 2021-02-07 19:13:49
问题 Is there a more efficient method in python to extract data from a nested python list such as A = array([[array([[12000000]])]], dtype=object) . I have been using A[0][0][0][0] , it does not seem to be an efficinet method when you have lots of data like A. I have also used numpy.squeeeze(array([[array([[12000000]])]], dtype=object)) but this gives me array(array([[12000000]]), dtype=object) PS: The nested array was generated by loadmat() function in scipy module to load a .mat file which

How to efficiently extract values from nested numpy arrays generated by loadmat function?

让人想犯罪 __ 提交于 2021-02-07 19:12:11
问题 Is there a more efficient method in python to extract data from a nested python list such as A = array([[array([[12000000]])]], dtype=object) . I have been using A[0][0][0][0] , it does not seem to be an efficinet method when you have lots of data like A. I have also used numpy.squeeeze(array([[array([[12000000]])]], dtype=object)) but this gives me array(array([[12000000]]), dtype=object) PS: The nested array was generated by loadmat() function in scipy module to load a .mat file which

In numpy, how to create an array of the indices of the elements in a source array as they are found in a destination array?

最后都变了- 提交于 2021-02-07 19:03:48
问题 I'm sure this question has been answered somewhere, but I just can't find the words to look for it. I have these two arrays: import numpy as np src = np.array([[8, 1], [2, 4]]) dst = np.array([[1, 4], [8, 2]]) I would like to get this array: indices = (np.array([[1, 0], [1, 0]]), np.array([[0, 0], [1, 1]])) Such that dst[indices] gets me src . Any ideas? Moreover, what is the kind of operation that I'm looking for called? So that I can search more about it by myself in the future. 回答1: Here

Improving frequency time normalization/hilbert transfer runtimes

Deadly 提交于 2021-02-07 18:42:38
问题 So this is a bit of a nitty gritty question... I have a time-series signal that has a non-uniform response spectrum that I need to whiten. I do this whitening using a frequency time normalization method, where I incrementally filter my signal between two frequency endpoints, using a constant narrow frequency band (~1/4 the lowest frequency end-member). I then find the envelope that characterizes each one of these narrow bands, and normalize that frequency component. I then rebuild my signal

Get indices of matrix from upper triangle

£可爱£侵袭症+ 提交于 2021-02-07 18:29:45
问题 I have a symmetric matrix represented as a numpy array, like the following example: [[ 1. 0.01735908 0.01628629 0.0183845 0.01678901 0.00990739 0.03326491 0.0167446 ] [ 0.01735908 1. 0.0213712 0.02364181 0.02603567 0.01807505 0.0130358 0.0107082 ] [ 0.01628629 0.0213712 1. 0.01293289 0.02041379 0.01791615 0.00991932 0.01632739] [ 0.0183845 0.02364181 0.01293289 1. 0.02429031 0.01190878 0.02007371 0.01399866] [ 0.01678901 0.02603567 0.02041379 0.02429031 1. 0.01496896 0.00924174 0.00698689] [