NumPy Input and Output: base_repr() function
numpy.base_repr() function
The base_repr() function is used to get a string representation of a number in the given base system.
Syntax:
numpy.base_repr(number, base=2, padding=0)
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
number | The value to convert. Positive and negative values are handled. int |
Required |
base | Convert number to the base number system. The valid range is 2-36, the default value is 2. int |
Optional |
padding | Number of zeros padded on the left. Default is 0 (no padding). int |
Optional |
Returns: out : str
String representation of number in base system.
NumPy.base_repr() method Example:
>>> import numpy as np
>>> np.base_repr(7)
Output:
'111'
NumPy.base_repr() method Example:
>>> import numpy as np
>>> np.base_repr(5, 5)
Output:
'10'
NumPy.base_repr() method Example:
>>> import numpy as np
>>> np.base_repr(5, base=5, padding=3)
Output:
'00010'
NumPy.base_repr() method Example:
>>> import numpy as np
>>> np.base_repr(12, base=16)
Output:
'C'
NumPy.base_repr() method Example:
>>> import numpy as np
>>> np.base_repr(34, base=16)
Output:
'22'
Python - NumPy Code Editor:
Previous: binary_repr() function
Next: datasource() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework