在 numpy 中,我可以执行以下操作:
>>> x = np.array([[False, True, False], [True, False, True]])
>>> z0 = np.logical_and.accumulate(x, axis=0)
>>> z1 = np.logical_and.accumulate(x, axis=1)
这将返回以下内容:
>>> z0
array([[False, True, False],
[False, False, False]])
>>> z1
array([[False, False, False],
[ True, False, False]])
这个ufunc操作在pytorch中相当于什么?
逻辑
and
对应于二进制形式的乘积。您可以使用 cumprod
来实现:
>>> x.cumprod(dim=0).bool()
tensor([[False, True, False],
[False, False, False]])
>>> x.cumprod(dim=1).bool()
tensor([[False, False, False],
[ True, False, False]])