# Reading a branch of arrays in PyROOT

**URL:** <https://root-forum.cern.ch/t/reading-a-branch-of-arrays-in-pyroot/44076>\
**Category:** Newbie\
**Created:** [March 19, 2021, 6:27pm UTC](https://root-forum.cern.ch/t/reading-a-branch-of-arrays-in-pyroot/44076 "2021-03-19T18:27:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChilufyaM](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bc79bd/32.png) [@ChilufyaM](https://root-forum.cern.ch/u/ChilufyaM)\
**Post date:** [March 19, 2021, 6:27pm UTC](https://root-forum.cern.ch/t/reading-a-branch-of-arrays-in-pyroot/44076/1 "2021-03-19T18:27:15Z")

</div>

Dear experts,

I’m trying to read a TBranch that was created with something like the following lines:

```auto
L = ROOT.TTree('name','name')
v=array('i',[0])
L.Branch('fibre',v, 'fibre/I')
for i in range(48):
     v[0] = i
     L.Fill()

#The branch looks like this:
************************
* Row * fibre *
************************
* 0 * 0 *
* 1 * 1 *
* 2 * 2 *
* 3 * 3 *
* 4 * 4 *
* 5 * 5 *
* 6 * 6 *
* 7 * 7 *
* 8 * 8 *
* 9 * 9 *
* 10 * 10 *
..................................

```

How can I read the elements on this branch? So far, I have tried something like:

```auto
ntuple = ROOT.TChain('L')
nEntries = ntuple.GetEntries()
for i in range (nEntries):
     x = ntuple.fibre[0]

```

And I get this TypeError: ‘int’ object is not subscriptable

Thanks for any help.  
Chilufya

---

<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:** [March 22, 2021, 8:27am UTC](https://root-forum.cern.ch/t/reading-a-branch-of-arrays-in-pyroot/44076/2 "2021-03-22T08:27:06Z")

</div>

The code you provided cannot be run and seems a bit to small to understand what’s going on. Can you provide something more complete ? Then @pcanal can help you.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 23, 2021, 12:25am UTC](https://root-forum.cern.ch/t/reading-a-branch-of-arrays-in-pyroot/44076/3 "2021-03-23T00:25:21Z")

</div>

```auto
ntuple = ROOT.TChain('L')
nEntries = ntuple.GetEntries()
for i in range (nEntries):
     x = ntuple.fibre

```

---

<div class="post-metadata">

**Author:** ![ChilufyaM](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bc79bd/32.png) [@ChilufyaM](https://root-forum.cern.ch/u/ChilufyaM)\
**Post date:** [March 23, 2021, 9:14am UTC](https://root-forum.cern.ch/t/reading-a-branch-of-arrays-in-pyroot/44076/4 "2021-03-23T09:14:51Z")

</div>

Thanks a lot and apologies for the delayed response.

I already did something similar to what you have suggested. I did this:

import ROOT  
import numpy as np  
ntuple = ROOT.TChain(‘L’)  
for event in ntuple:  
x = np.asarray([ntuple.fibre])[0]
