x1 = np.array([0, 1, 0, 1, 0, 1, 0, 1, 1, 1])
y = np.array([-1, -1, -1, -1, -1, 1, 1, 1, 1, -1])
Run Code Online (Sandbox Code Playgroud)
我知道使用这两个数组,您可以总结在这行代码中精确指标与numpy相等的次数.
np.sum(x1 == y)
Run Code Online (Sandbox Code Playgroud)
但有没有办法总结每次相同的索引等于每个数组上的特定值,如
np.sum(x1 == 1 && y == -1)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这行代码没有运行,但是如果它工作,结果应该是3.