首页 > 其他分享 >无涯教程-NumPy - 右移运算符函数

无涯教程-NumPy - 右移运算符函数

时间:2023-10-17 20:03:57浏览次数:44  
标签:右移 Binary right shift 无涯 40 运算符 np print

numpy.right_shift()函数将数组元素的二进制表示形式向右移动指定的位置,并在左侧添加相等数量的0。

import numpy as np 

print 'Right shift 40 by two positions:' 
print np.right_shift(40,2) 
print '\n'  

print 'Binary representation of 40:' 
print np.binary_repr(40, width=8) 
print '\n'  

print 'Binary representation of 10' 
print np.binary_repr(10, width=8)  
# Two bits in '00001010' are shifted to right and two 0s appended from left.

其输出如下-

Right shift 40 by two positions:
10

Binary representation of 40:
00101000

Binary representation of 10
00001010

参考链接

https://www.learnfk.com/numpy/numpy-right-shift.html

标签:右移,Binary,right,shift,无涯,40,运算符,np,print
From: https://blog.51cto.com/u_14033984/7908623

相关文章

  • 无涯教程-NumPy - 左移运算符函数
    numpy.left_shift()函数将数组元素的二进制向左移动指定位置,从右边追加等号0。importnumpyasnpprint'Leftshiftof10bytwopositions:'printnp.left_shift(10,2)print'\n'print'Binaryrepresentationof10:'printnp.binary_repr(10,width=......
  • 无涯教程-NumPy - delete函数
    此函数返回一个新数组,其中指定的子数组已从数组中删除,与insert()函数一样,如果不使用axis参数,则将输入数组展平,该函数采用以下参数-Numpy.delete(arr,obj,axis)Sr.No.Parameter&描述1arr输入数组2obj可以是切片,整数或整数数组,指示要从输入数组中删除的子数组3......
  • 无涯教程-NumPy - resize函数
    此函数返回具有指定大小的新数组,该函数采用以下参数。numpy.resize(arr,shape)Sr.No.描述1arr输入数组要调整大小2shape输出数组的新维度importnumpyasnpa=np.array([[1,2,3],[4,5,6]])print'Firstarray:'printaprint'\n'print'Theshapeo......
  • 无涯教程-NumPy - broadcast_to函数
    此功能将数组广播为新维度,它返回原始数组的只读视图,如果新维度不符合NumPy的广播规则,则该函数可能会引发ValueError。注意-此功能自版本1.10.0起可用。该函数采用以下参数。numpy.broadcast_to(array,shape,subok)importnumpyasnpa=np.arange(4).reshape(1,4)prin......
  • 无涯教程-NumPy - swapaxes函数
    此函数互换数组的两个轴,对于1.10之后的NumPy版本,将返回交换数组的视图,该函数采用以下参数。numpy.swapaxes(arr,axis1,axis2)Sr.No.Parameter&描述1arr要交换其轴的输入数组2axis1与第一个轴对应的int3axis2与第二个轴对应的int#Itcreatesa3dimen......
  • 无涯教程-NumPy - rollaxis函数
    此功能使指定的轴向后滚动,直到它位于指定的位置,该函数具有三个参数。numpy.rollaxis(arr,axis,start)Sr.No.Parameter&描述1arr输入数组2axis轴向后滚动。其他轴的位置相对彼此不变3start默认情况下为零,以完成整个滚动。滚动直到到达指定位置#Itcreate......
  • 无涯教程-NumPy - reshape函数
    此函数在不更改数据的情况下为数组提供了新的维度,它接受以下参数-numpy.reshape(arr,newshape,order')Sr.No.描述1arr数组2newshapeint或int的元组,新维度应与原始维度兼容3order如果数组存储在类似Fortran的连续内存中,则"C"表示C风格,"F"表示Fortran风格,"......
  • 无涯教程-NumPy - Matplotlib
    Matplotlib是Python的绘图库,它与NumPy一起使用,提供了一个环境,是MatLab的有效开源替代方案,它可以与PyQt和wxPython等图形工具包一起使用Matplotlib模块最初由JohnD.Hunter编写。自2012年以来,MichaelDroettboom是主要开发人员。目前,Matplotlib版本。1.5.1是可用的稳定版本。......
  • 测试左移右移-理论篇
    目录前言一、浅解左移1.什么是测试左移?1.1对产品1.2对开发1.3对测试1.4对运维二、浅解右移1.1对产品1.2对开发1.3对测试1.4对运维三、总结前言测试左移右移,很多人说能让测试更拥有主动权,展示出测试岗位也是有很大的价值,说白了就是整体效率与质量保障。其实不然,是测试业界的一种......
  • 无涯教程-NumPy - 算术运算
    用于执行算术运算(如add(),subtract(),multipli()和divide())的输入数组必须具有相同的维度或符合数组broadcasting规则。importnumpyasnpa=np.arange(9,dtype=np.float_).reshape(3,3)print'Firstarray:'printaprint'\n'print'Secondarray:'b=......