我有這樣的結構:遍歷狀結構樹
[
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.])
]
]
]
(其中array
s爲numpy.array
S)
如何編寫一個生成器,給我:
(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)
到目前爲止,我唯一擁有的是:
def loop_bin(bins):
for i in range(len(bins)-1):
yield [bins[i], bins[i+1]]
什麼是*數組* *?爲什麼第3行和第4行是相同的? – hochl
'array'是'np.array' –
您是否知道itertools? http://docs.python.org/library/itertools.html –