Home > other >  Python with loop generated binary tree price all paths
Python with loop generated binary tree price all paths

Time:11-19

N=2, the binary tree is:
The tree=array ([[1, 1.2, 1.4],
[0, 0.8, 1],
[0, 0, 0.6]])
I use iteration. The product can generate all of the 4 possible:
The from itertools import product
A=np. Array (list (product ((0, 1), repeat=N)))
A=np. C_ [[0] * * * N (2), a]
A=a.c umsum (axis=1)
B=np. Choose (a tree)
The result is:
[[1. 1.2 1.4]
/1. 1.2 1.
/1. 0.8 1.
[1. 0.8 0.6]]
Can be performed when N is small, but this method when N=30 or 50 ran not to come out, and through bosses to help solve the loop
  • Related