反转使用numpy的布尔数组〜 [英] Inverting a numpy boolean array using ~
问题描述
我可以使用〜A
反转,而不是比较尴尬功能布尔的numpy的阵列, np.logical_and()
和 np.invert()
?事实上,〜
看起来做工精细,但我找不到它的任何nympy参考手册,以及 - 更令人震惊 - 它当然不会的不的与标量的工作(如布尔(〜真)
收益真
!),所以我有点担心。 ..
简短的回答:YES
编号:
<一个href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.invert.html\">http://docs.scipy.org/doc/numpy/reference/generated/numpy.invert.html
注意:
计算逐位不输入数组的整数的基本二元再presentation。这ufunc实现C / Python的符〜。
块引用>和
bitwise_not是倒置的别名:
块引用>&GT;&GT; np.bitwise_not是np.invert
&GT;&GT;真正Can I use
~A
to invert a numpy array of booleans, instead of the rather awkward functionsnp.logical_and()
andnp.invert()
? Indeed,~
seems to work fine, but I can't find it in any nympy reference manual, and - more alarmingly - it certainly does not work with scalars (e.g.bool(~True)
returnsTrue
!), so I'm a little bit worried ...解决方案short answer: YES
Ref:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.invert.html
Notice:
Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ~.
and
bitwise_not is an alias for invert:
>> np.bitwise_not is np.invert >> True
这篇关于反转使用numpy的布尔数组〜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!