[英]Why doesn't numpy.where give me the correct answer?
我試圖估計穿過“壁”的中子的數量,而不會被初學者反射或吸收,但是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]
問題並沒有停止。
這不是您的大問題的一部分,但是可以簡化此塊:
if np.where(Tabx[iActif] > 1)[0].size!=0:
actif[np.where(Tabx[iActif] > 1)[0]]=False
至
actif[ Tabx[iActif]>1] = False
但是您沒有做任何描述該做的事情,也沒有做錯什么的嘗試。 我不知道什么是“正確的人”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.