如何使用NumPy获得累积分布函数?

编程入门 行业动态 更新时间:2024-10-23 15:27:23
本文介绍了如何使用NumPy获得累积分布函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用NumPy创建CDF,下一个是我的代码:

I want to create a CDF with NumPy, my code is the next:

histo = np.zeros(4096, dtype = np.int32) for x in range(0, width): for y in range(0, height): histo[data[x][y]] += 1 q = 0 cdf = list() for i in histo: q = q + i cdf.append(q)

我正在数组旁边走,但是要花很长时间执行程序.具有此功能的内置功能,不是吗?

I am walking by the array but take a long time the program execution. There is a built function with this feature, isn't?

推荐答案

我不太确定您的代码在做什么,但是如果您有numpy.histogram返回的hist和bin_edges数组,则可以使用numpy.cumsum生成直方图内容的累积和.

I'm not really sure what your code is doing, but if you have hist and bin_edges arrays returned by numpy.histogram you can use numpy.cumsum to generate a cumulative sum of the histogram contents.

>>> import numpy as np >>> hist, bin_edges = np.histogram(np.random.randint(0,10,100), normed=True) >>> bin_edges array([ 0. , 0.9, 1.8, 2.7, 3.6, 4.5, 5.4, 6.3, 7.2, 8.1, 9. ]) >>> hist array([ 0.14444444, 0.11111111, 0.11111111, 0.1 , 0.1 , 0.14444444, 0.14444444, 0.08888889, 0.03333333, 0.13333333]) >>> np.cumsum(hist) array([ 0.14444444, 0.25555556, 0.36666667, 0.46666667, 0.56666667, 0.71111111, 0.85555556, 0.94444444, 0.97777778, 1.11111111])

更多推荐

如何使用NumPy获得累积分布函数?

本文发布于:2023-11-30 02:53:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   函数   NumPy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!