VOOZH about

URL: https://www.geeksforgeeks.org/python/numpy-base_repr-in-python/

⇱ numpy.base_repr() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

numpy.base_repr() in Python

Last Updated : 29 Nov, 2018
numpy.base_repr(number, base=2, padding=0) function is used to return a string representation of a number in the given base system. For example, decimal number 10 is represented as 1010 in binary whereas it is represented as 12 in octal.
Syntax : numpy.base_repr(number, base=2, padding=0) Parameters : number : Input number. Only an integer decimal number can be used as input. base : [int, optional] Convert number to the base number system. The valid range is 2-36, the default value is 2. padding : [int, optional] To add number of zeroes on the left. Default is 0. Return : String representation of the input number in base system.
Code #1 : Working Output :
Input number : 10
binary representation of 10 : 1010
  Code #2 :
Output :
Input array : [5, -8, 21]

binary representation of 5
Without using padding parameter : 101
Using padding parameter: 000101

octal representation of -8
Without using padding parameter : -10
Using padding parameter : -000010

hexa-decimal representation of 21
Without using padding parameter : 15
Using padding parameter : 00015
Comment
Article Tags: