Python: Binning data with a weight

923 views Asked by At

I have got a dataset with strong noise, e.g.

import numpy as np
import matplotlib.pyplot as plt

N = 1000
x = np.linspace(0,10,N)
y = x + 20 * np.random.rand(N)

I want to bin the data for a given binsize (or binnumber). By that I basically just mean a Δx. The binned data should be weighted by a gaussian function that you can think of as a gaussian that is extended over the y-axis weighting the data depending on the distance of the expectation value µ. Also, I want the data to give me the 1σ-error.

I know about numpy.digitize and scipy.stats.binned_statistic but I am failing to apply any of the two to get my desired binning. Maybe the latter should be the easiest to use for this case as it offers the parameter statistic=<function> but I am open to suggestions.

0

There are 0 answers