Wuschelbeutel Kartoffelhuhn 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

. Can I now augment the histogram with an additional pair of two lists
so that the histogram contains both

The relevant and official documentation is here:
On this page I only see parameters and returns, but not functions that this object supports. How can I find all the supported functions?

Answer Source

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