Fitting a weighted histogram with a normal distribution

China☆狼群 提交于 2019-12-11 11:03:03

问题


I know how to fit the data entering an histogram with a normal distribution using the SCipy library (Fitting a histogram with python) but how could I do the same if on top of having data I have an array of weights having the same dimension. Is there a proper function for that or should I create a second array fed by the data and weighting it myself?

Cheers.

Edit:

This is pretty much already answered here:

Weighted standard deviation in NumPy?


回答1:


just use the weights paramater on scipy.histogram and pass in your array of weights:

scipy.stats.histogram(a, numbins=10, defaultlimits=None, weights=None, printextras=False)

from the docs:

weights : array_like, optional The weights for each value in a. Default is None, which gives each value a weight of 1.0


NOTE: as of v1.0, scipy does not have the function histogram, but as of v1.11 histogram appears in numpy, with a similar (but not identical) call signature that includes the weights= argument:

numpy.histogram(a, bins=10, range=None, normed=False, weights=None, density=None)


来源:https://stackoverflow.com/questions/21063935/fitting-a-weighted-histogram-with-a-normal-distribution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!