为什么不numpy.where给我正确的答案?

时间:2015-10-19 21:24:43

标签: python numpy where

我试图估算穿过墙壁的中子的数量"没有被初学者反映或吸收,但var root = treeData[0]; root.x0 = height / 2; root.y0 = 0; var root2 = treeData2[0]; root2.x0 = height / 2; root2.y0 = 0; collapse(root); root2.children.forEach(collapse); update(root2, tree2, root2, -500., -1, "nodeD", "linkD", j); update(root, tree, root, -500, 1, "nodeA", "linkA", i); // Toggle children on click. function click(d, source, mytree, myroot, position, symmetry, myclass, mylinks, ii) { if (d.children) { d._children = d.children; d.children = null; } else { d.children = d._children; d._children = null; } update(d, source, mytree, myroot, position, symmetry, myclass, mylinks, ii); //centerNode(root); //centerNode(root2); } 没有给我正确答案:

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)

问题并没有停止。

1 个答案:

答案 0 :(得分:0)

这不是您的大问题的一部分,但可能会简化此块:

if np.where(Tabx[iActif] > 1)[0].size!=0:
    actif[np.where(Tabx[iActif] > 1)[0]]=False

actif[ Tabx[iActif]>1] = False

但是你没有试图描述这应该做什么,也不知道它究竟做错了什么。我不知道'正确'是什么。