NumPy 位运算符2024 年 8 月 29 日 | 阅读 3 分钟 Numpy 提供了以下位运算符。
bitwise_and 运算NumPy 提供了 bitwise_and() 函数,用于计算两个操作数的按位与运算。 按位与运算是对操作数二进制表示的对应位执行的。如果操作数中的对应位都设置为 1,则 AND 结果中的结果位才设置为 1,否则设置为 0。 示例输出 binary representation of a: 0b1010 binary representation of b: 0b1100 Bitwise-and of a and b: 8 AND 真值表当且仅当两个位都为 1 时,两个位的 AND 结果才为 1,否则为 0。
bitwise_or 运算符NumPy 提供了 bitwise_or() 函数,用于计算两个操作数的按位或运算。 按位或运算是对操作数二进制表示的对应位执行的。如果操作数中的对应位之一设置为 1,则 OR 结果中的结果位将设置为 1;否则将设置为 0。 示例输出 binary representation of a: 0b110010 binary representation of b: 0b1011010 Bitwise-or of a and b: 122 或真值表如果其中一个位为 1,则两个位的 OR 结果为 1,否则为 0。
取反运算用于计算给定操作数的按位取反运算。如果函数中传递了带符号整数,则返回 2 的补码。 请看以下示例。 示例输出 Binary representation: 00010100 [235] Binary representation: 11101011 它将操作数二进制表示中的位向左移动指定的位置。从右侧追加相同数量的 0。考虑以下示例。 示例输出 left shift of 20 by 3 bits 160 Binary representation of 20 in 8 bits 00010100 Binary representation of 160 in 8 bits 10100000 右移运算它将操作数二进制表示中的位向右移动指定的位置。从左侧追加相同数量的 0。考虑以下示例。 示例输出 left shift of 20 by 3 bits 2 Binary representation of 20 in 8 bits 00010100 Binary representation of 160 in 8 bits 10100000 下一主题NumPy 字符串函数 |
我们请求您订阅我们的新闻通讯以获取最新更新。