是否可以更新/添加已填充的numpy直方图(特别是numpy.histogram2d)?

Wus*_*uhn 4 python numpy histogram

我已经用一对列表填充了numpy.histogram2d (x0,y0).我现在可以使用另外一对两个列表来增加直方图,(x1,y1)以便直方图包含(x0,y0)(x1,y1)吗?

相关的官方文档在这里:https: //docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html 在这个页面上我只看到参数和返回,但不是这个对象支持的函数.如何找到所有支持的功能?

jot*_*asi 7

np.histogram2D不是评论中指出的对象.它是一个函数,它返回一个带bin值的数组,以及bin边缘的两个值.尽管如此,只要您不计算标准直方图,您就可以简单地使用相同的二进制数添加到直方图中.例如,要从np.histogram2d文档中扩展示例:

import numpy as np

x = np.random.normal(3, 1, 100)
y = np.random.normal(1, 1, 100)

xedges = [0, 1, 1.5, 3, 5]
yedges = [0, 2, 3, 4, 6]

H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))

x2 = np.random.normal(3, 1, 100)
y2 = np.random.normal(1, 1, 100)

H += np.histogram2d(x2, y2, bins=(xedges, yedges))[0]
Run Code Online (Sandbox Code Playgroud)

这将为您H提供bin边缘xedges和中添加的组合bin值yedges.