简体   繁体   English

Python numpy boolean 数组不是整个列和行

[英]Python numpy boolean array not whole columns and rows

I want to apply the NOT operation on whole columns/rows of a boolean Numpy array .我想对boolean Numpy 数组的整列/行应用NOT操作。 Is this possible with Numpy? Numpy 可以吗?

matrix = np.array([[False for i in range(3)] for j in range(2)])
# Initial
# [False, False, False]
# [False, False, False]

matrix[:,1].not() # Something like this
# After not operation on column 1
# [False, True, False]
# [False, True, False]

This should do the trick, see here这应该可以解决问题,请参见此处

matrix[:, 1] = np.logical_not(matrix[:, 1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM