Im going to hazard a guess that your problem is u**(N-i). Large exponents are notoriously poor performers, I would first look to restructure that aspect of the code and then isolate other poorly performant sections afterwards.
For example you might observe that:
S_T[i] = S0 * u**(N-i) * d**(i)
is equivalent to:
S_T[i] = S0 * u**N * (d/u)**i
then u**N ...