-
拉莫斯之舞
在完美的工具存在:np.logical_and.accumulate(survival,axis=1)例子 :array([[False, True, False, True], [ True, True, False, True], [False, True, True, True], [False, True, False, False], [ True, False, False, False], [False, True, True, True], [False, False, True, False], [False, False, True, True]])=>array([[False, False, False, False], [ True, True, False, False], [False, False, False, False], [False, False, False, False], [ True, False, False, False], [False, False, False, False], [False, False, False, False], [False, False, False, False]])
-
慕尼黑的夜晚无繁华
使用fornumpy 数组时尽量不要使用纯循环。改用cumulative product反对axis=1arr.cumprod(1).astype(np.bool)
-
慕勒3428872
>>> mc = (8, 4)>>> survival = np.random.random(mc) > np.random.random(mc)>>> survivalarray([[ True, True, True, True], [ True, False, False, True], [ True, False, True, True], [ True, False, True, False], [False, True, False, False], [ True, True, False, True], [ True, True, False, False], [False, False, True, True]])和>>> death = [x.tolist().index(False) if False in x else -1 for x in survival]>>> [s[ : d].tolist() + [False] * (survival.shape[1] - d) if d != -1 else s.tolist() for s, d in zip(survival, death)][[True, True, True, True], [True, False, False, False], [True, False, False, False], [True, False, False, False], [False, False, False, False], [True, True, False, False], [True, True, False, False], [False, False, False, False]]