w3resource

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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/numpy/input-and-output/base_repr.php