numpy.left_shift() in Python Last Updated : 28 Nov, 2018 Comments Improve Suggest changes Like Article Like Report numpy.left_shift() function is used to Shift the bits of an integer to the left. The bits are shifted to the left by appending arr2 0s(zeroes) at the right of arr1. Since the internal representation of numbers is in binary format, this operation is equivalent to multiplying arr1 by 2**arr2. For example, if the number is 5 and we want to 2 bit left shift then after left shift 2 bit the result will be 5*(2^2) = 20 Syntax : numpy.left_shift(arr1, arr2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, ufunc ‘left_shift’) Parameters : arr1 : array_like of integer type arr2 : array_like of integer type Number of zeros to append to arr1.The value of arr2 should be positive integer. out : [ndarray, optional] A location into which the result is stored. -> If provided, it must have a shape that the inputs broadcast to. -> If not provided or None, a freshly-allocated array is returned. **kwargs : allows you to pass keyword variable length of argument to a function. It is used when we want to handle named argument in a function. where : [array_like, optional]True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone. Return : array of integer type. Return arr1 with bits shifted arr2 times to the left. This is a scalar if both arr1 and arr2 are scalars. Code #1 : Working Python # Python program explaining # left_shift() function import numpy as geek in_num = 5 bit_shift = 2 print ("Input number : ", in_num) print ("Number of bit shift : ", bit_shift ) out_num = geek.left_shift(in_num, bit_shift) print ("After left shifting 2 bit : ", out_num) Output : Input number : 5 Number of bit shift : 2 After left shifting 2 bit : 20 Code #2 : Python # Python program explaining # left_shift() function import numpy as geek in_arr = [2, 8, 15] bit_shift =[3, 4, 5] print ("Input array : ", in_arr) print ("Number of bit shift : ", bit_shift) out_arr = geek.left_shift(in_arr, bit_shift) print ("Output array after left shifting: ", out_arr) Output : Input array : [2, 8, 15] Number of bit shift : [3, 4, 5] Output array after left shifting: [ 16 128 480] Comment More infoAdvertise with us Next Article numpy.left_shift() in Python jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-Binary Operation Practice Tags : python Similar Reads numpy.right_shift() in Python numpy.right_shift() function is used to Shift the bits of an integer to the right. Because the internal representation of numbers is in binary format, this operation is equivalent to dividing arr1 by 2**arr2. For example, if the number is 20 and we want to 2-bit right shift then after right shift 2- 2 min read Python | Numpy numpy.ndarray.__rshift__() With the help of numpy.ndarray.__rshift__() method, we can get the elements that is right shifted by the value that is provided as a parameter in numpy.ndarray.__rshift__() method. Syntax: ndarray.__rshift__($self, value, /) Return: self>>value Example #1 : In this example we can see that ever 1 min read Python | Pandas Index.shift() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.shift() function shift index by desired number of time frequency incremen 2 min read Python | Numpy MaskedArray.__rshift__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rshift__ method we can get the elements that is right shifted by the value that is provided as a parameter. Syntax: numpy.MaskedArray.__rshift__ Return: 1 min read numpy.roll() in Python The numpy.roll() function rolls array elements along the specified axis. Basically what happens is that elements of the input array are being shifted. If an element is being rolled first to the last position, it is rolled back to the first position. Syntax : numpy.roll(array, shift, axis = None) Par 2 min read Python | Numpy MaskedArray.__rlshift__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rlshift__ method we can get the elements that is right shifted by the value that is provided as a parameter. Syntax: numpy.MaskedArray.__rlshift__ Retur 1 min read Python | Numpy MaskedArray.__rrshift__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rrshift__ method we can get the elements that is right shifted by the value that is provided as a parameter. Syntax: numpy.MaskedArray.__rrshift__ Retur 1 min read turtle.left() method in Python The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.left() The turtle.left() method is used to change the direction of the turtl 2 min read numpy.trim_zeros() in Python numpy.trim_zeros function is used to trim the leading and/or trailing zeros from a 1-D array or sequence. Syntax: numpy.trim_zeros(arr, trim) Parameters: arr : 1-D array or sequence trim : trim is an optional parameter with default value to be 'fb'(front and back) we can either select 'f'(front) and 2 min read Python | Decimal shift() method Decimal#shift() : shift() is a Decimal class method which returns the shifted copy of x, y times Syntax: Decimal.shift() Parameter: Decimal values Return: the shifted copy of x, y times Code #1 : Example for shift() method Python3 # Python Program explaining # shift() method # loading decimal librar 2 min read Like