I’ve this kind of structure:
[
array([ 0. , 4.5, 9. ]),
[
array([ 100., 120., 140.]),
[
array([ 1000., 1100., 1200.]),
array([ 1200., 1300., 1400.])
],
array([ 150., 170., 190.]),
[
array([ 1500., 1600., 1700.]),
array([ 1700., 1800.])
]
]
]
(where arrays are numpy.arrays)
how to write a generator that give me:
(0, 4.5), (100, 120), (1000, 1100)
(0, 4.5), (100, 120), (1100, 1200)
(0, 4.5), (120, 140), (1200, 1300)
(0, 4.5), (120, 140), (1300, 1400)
(4.5, 9), (150, 170), (1500, 1600)
(4.5, 9), (150, 170), (1600, 1700)
(4.5, 9), (170, 190), (1700, 1800)
by now, the only thig I have is:
def loop_bin(bins):
for i in range(len(bins)-1):
yield [bins[i], bins[i+1]]
What about:
The
tuplethings are for pretty print, in order to get closer to your example. I was not very sure on the criteria to use for detecting a leaf. Note also that I made my experiments with the following pythonic array:rather than the numpy array given, but the changes to get things running with numarray should be straightforward.