反转使用numpy的布尔数组〜 [英] Inverting a numpy boolean array using ~

查看:1816
本文介绍了反转使用numpy的布尔数组〜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用〜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 functions np.logical_and() and np.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) returns True !), 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆