如何在numpy中对张量矩阵进行按位和运算

问题描述 投票:2回答:1

我有以下numpy张量:

M = np.zeros((a,b,c), dtype=bool)

我希望在尺寸为a的所有b,c矩阵上执行一个按位,以得到尺寸为b,c的最终矩阵。我不知道如何有效地实现这一目标。就像是

np.apply_along_axis(func1d=np.bitwise_and, axis=0, arr=M),但我收到错误消息:ValueError: invalid number of arguments,我不明白为什么。

更新:这是有效的,但有更多(时间)有效的方式吗?

v = np.ones((b,c),dtype=bool)
for i in range(0, a):
  v = v & M[i]
python numpy matrix bitwise-operators logical-operators
1个回答
1
投票

您可以使用all

>> M = np.zeros((8,9,10), dtype=np.bool)
>> M.all(0).shape
(9, 10)
© www.soinside.com 2019 - 2024. All rights reserved.