# Creating an array with the name of the histograms inside a .root file

**URL:** <https://root-forum.cern.ch/t/creating-an-array-with-the-name-of-the-histograms-inside-a-root-file/50028>\
**Category:** Newbie\
**Tags:** python, root\
**Created:** [May 19, 2022, 1:42pm UTC](https://root-forum.cern.ch/t/creating-an-array-with-the-name-of-the-histograms-inside-a-root-file/50028 "2022-05-19T13:42:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daumann](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Daumann](https://root-forum.cern.ch/u/Daumann)\
**Post date:** [May 19, 2022, 1:42pm UTC](https://root-forum.cern.ch/t/creating-an-array-with-the-name-of-the-histograms-inside-a-root-file/50028/1 "2022-05-19T13:42:35Z")

</div>

Dear experts,

I need to do some operations with the histograms in a file that has almost 300k histograms in it. doing it in pure python takes a very long time, so I would want to create a NumPy array that stores the names of the histograms so I can make the operations that I wish to.

But the only thing I could come up with is an np array of keys:

```auto
test = np.array( (file.GetListOfKeys()) )

```

there is some function like .GetNames() or something that I could use? I tried something like

```auto
test = np.array( (file.GetListOfKeys()).GetName() )

```

but I guess it does not work in an element by element inside the array. I need to get a string array with the name of the histograms to separate and cluster the histograms the way i need to. Any tips on that?

Best regards,  
Caio.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 19, 2022, 1:48pm UTC](https://root-forum.cern.ch/t/creating-an-array-with-the-name-of-the-histograms-inside-a-root-file/50028/2 "2022-05-19T13:48:21Z")

</div>

I am not sure how to do that in Python. May be @etejedor knows.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [May 19, 2022, 2:16pm UTC](https://root-forum.cern.ch/t/creating-an-array-with-the-name-of-the-histograms-inside-a-root-file/50028/3 "2022-05-19T14:16:28Z")

</div>

Hello,

To get all those names in Python you would still need to loop over the TList, which would be slow anyway. If you need to loop over 300k keys of a TFile, it is probably better that you do it in C++.

---

<div class="post-metadata">

**Author:** ![Daumann](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Daumann](https://root-forum.cern.ch/u/Daumann)\
**Post date:** [May 19, 2022, 2:18pm UTC](https://root-forum.cern.ch/t/creating-an-array-with-the-name-of-the-histograms-inside-a-root-file/50028/4 "2022-05-19T14:18:33Z")

</div>

ok, got it! I will write a c++ script then.
