Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Support for THn and THnSparse in hist2array #237

Merged
merged 6 commits into from Apr 4, 2016
Merged

Conversation

ndawe
Copy link
Member

@ndawe ndawe commented Apr 4, 2016

As requested by @cbourjau in #188 this PR adds support for THn and THnSparse (with #arbitrary dimensionality) in hist2array:

>>> from root_numpy import array2hist, hist2array
>>> import numpy as np
>>> from rootpy.plotting import Hist2D
>>> hist = Hist2D(5, 0, 1, 3, 0, 1, type='F')
>>> array = np.random.randint(0, 10, size=(7, 5))
>>> array
array([[0, 4, 3, 5, 2],
       [2, 4, 4, 1, 2],
       [8, 1, 3, 4, 8],
       [1, 3, 0, 2, 3],
       [1, 8, 5, 6, 8],
       [4, 7, 8, 4, 5],
       [8, 7, 1, 4, 5]])
>>> array2hist(array, hist)
Hist2D('Hist2D_EJWHJJNmSmHPVeeiWtzFkT')
>>> hist2array(hist)
array([[ 4.,  4.,  1.],
       [ 1.,  3.,  4.],
       [ 3.,  0.,  2.],
       [ 8.,  5.,  6.],
       [ 7.,  8.,  4.]], dtype=float32)
>>> import ROOT
>>> hist2array(ROOT.THn.CreateHn("", "", hist))   # <=== same result
array([[ 4.,  4.,  1.],
       [ 1.,  3.,  4.],
       [ 3.,  0.,  2.],
       [ 8.,  5.,  6.],
       [ 7.,  8.,  4.]], dtype=float32)
>>> hist2array(ROOT.THnSparse.CreateSparse("", "", hist))   # <=== same result
array([[ 4.,  4.,  1.],
       [ 1.,  3.,  4.],
       [ 3.,  0.,  2.],
       [ 8.,  5.,  6.],
       [ 7.,  8.,  4.]], dtype=float32)

@ndawe ndawe mentioned this pull request Apr 4, 2016
2 tasks
@ndawe ndawe merged commit 067e9a9 into scikit-hep:master Apr 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant