【发布时间】:2015-10-19 21:24:42
【问题描述】:
我正在尝试估计穿过“墙”而没有被反射或吸收的中子数量,但是,numpy.where 并没有给我正确的答案:
import numpy as np
Tabx = np.zeros(10)
Tabcos = np.ones(10)
actif = np.ones(10, dtype=bool)
iActif = np.where(actif)[0]
pa = 0
ps = 0
for i in range(15):
iActif = np.where(actif)[0]
r = np.random.random(10)
l = -1 * 0.2 * np.log(r[iActif])
Tabx[iActif] += l * Tabcos[iActif]
if np.where(Tabx[iActif] > 1)[0].size!=0:
actif[np.where(Tabx[iActif] > 1)[0]]=False
print("itération: ", i + 1)
print(Tabx)
print(actif)
print(iActif)
我只会在它开始出错时显示:
itération: 6
[ 1.34250751 1.22131969 0.61147827 0.72320522 1.18101783 0.2767469
1.87170912 0.68726641 1.44933786 1.25179186]
[False False False False False False True True True True]
[3 6 7 8 9]
问题并没有停止。
【问题讨论】:
-
到底是什么问题?看起来
iActif比actif落后一步。 -
有时是有时不是。
-
你知道怎么解决吗?因为,我的问题是它没有给我正确的,因为它们没有超过 1. ,所以当我继续我的代码时它不起作用。