numpy的按位AND矩阵行为不同

在计算2个矩阵的按位与时,有时会得到结果,有时会出现错误,并且我不太明白为什么。这里有两个例子:

第一个:

a = np.array([0,1,1]).reshape(3,4)
b = np.array([0,0]).reshape(3,4)
np.bitwise_and(a,b)

给我正确的结果。

而第二个:

a = np.array(np.zeros(shape=(2,2)))
b = np.array(np.ones(shape=(2,2)))
np.bitwise_and(a,b)

给我以下错误:

TypeError: ufunc 'bitwise_and' not supported for the input types,and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

有人可以向我解释第一个示例与第二个示例之间的差异吗?为什么我会出错?

hanbaoling76 回答:numpy的按位AND矩阵行为不同

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3121590.html

大家都在问