Wuschelbeutel Kartoffelhuhn - 1 year ago 144
Python Question

# Is it possible to update / add to a numpy histogram (specifically, numpy.histogram2d) that is already populated?

I have already populated a numpy.histogram2d with a pair of lists

`(x0,y0)`
. Can I now augment the histogram with an additional pair of two lists
`(x1,y1)`
so that the histogram contains both
`(x0,y0)`
and
`(x1,y1)`
?

The relevant and official documentation is here:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html
On this page I only see parameters and returns, but not functions that this object supports. How can I find all the supported functions?

`np.histogram2D` is not an object as pointed out in the comments. It is a function that returns an array with bin values as well as two for the bin edges. Nonetheless, as long as you do not compute a normed histogram, you can simply add to the histogram with the same bins. For example, to extend the example from the `np.histogram2d` documentation:

``````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]
``````

This will give you the added combined bin values in `H` with bin edges `xedges` and `yedges`.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download