DEV Community

es404020
es404020

Posted on

Using Numpy histogram2d

Histogram2d is a Numpy function used in group two by two matrix based on certain bin conditions.

For Example

a=np.array([0.00, 1.00, 1.00, 0.98, 0.04, 0.85, 1.00, 1.00, 1.00, 0.36, 1.00,
       1.00, 1.00, 0.00, 0.63, 1.00, 0.00, 0.15, 1.00])

b=np.array([0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1])


bins=np.array([0,0.5,1])

Enter fullscreen mode Exit fullscreen mode

BINS : means from 0 - 0.4 is 0 and 0.5 to 1 is one


cm = np.histogram2d(a,b), bins=bins)[0]

array([[5.00, 1.00],
       [1.00, 12.00]])

Enter fullscreen mode Exit fullscreen mode

Top comments (0)