Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个名为“掩码”的 numpy 掩码数组,我想知道如何计算掩码中 True 或 False 值的数量?
掩码变量是在遍历不同数据集时创建的,因此如果它适用于任何随机数组大小,将会很有帮助。
这很简单:
import numpy as np # create random T/F array Q = np.random.choice([True, False], (100, 100)) n_true = Q.sum()