Inverting a numpy boolean array using ~

后端 未结 1 518
自闭症患者
自闭症患者 2020-12-05 09:17

Can I use ~A to invert a numpy array of booleans, instead of the rather awkward functions np.logical_and() and np.invert()? Indeed,

相关标签:
1条回答
  • 2020-12-05 09:53

    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
    
    0 讨论(0)
提交回复
热议问题