Seb*_*bMa -1 python matlab numpy xor
这是matlab代码:
A=[1,2,3,4];
B=[5,3];
bitxor(A,B')
Run Code Online (Sandbox Code Playgroud)
它返回:
ans =
4 7 6 1
2 1 0 7
Run Code Online (Sandbox Code Playgroud)
如何在没有循环的情况下使用numpy?
你要 np.bitwise_xor.outer(B, A)
或者,A ^ B[:,np.newaxis]工作,对于1D阵列是相同的.B[:,np.newaxis]生成一个具有形状的数组,根据需要与形状一起(2, 1)广播以产生形状输出.A(4,)(2, 4)