N=2時,二叉樹是:
tree = array([[1, 1.2, 1.4],
[0, 0.8, 1],
[0, 0, 0.6]])
我用iteration.product可以生成所有的4種可能:
from itertools import product
a = np.array(list(product((0, 1), repeat=N)))
a = np.c_[[0] * (2**N), a]
a = a.cumsum(axis=1)
b = np.choose(a,tree)
結果為:
[[1. 1.2 1.4]
[1. 1.2 1. ]
[1. 0.8 1. ]
[1. 0.8 0.6]]
當N比較小的時候是可以執行的,但當n=30或者50的時候這個方法就跑不出來了,求大佬幫忙用loop解決下
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/11768.html
