numpy.base_repr#
- numpy.base_repr(number, base=2, padding=0)[源代码]#
返回给定基数系统中数字的字符串表示形式.
- 参数:
- numberint
要转换的值.处理正值和负值.
- baseint, optional
将
number转换为 base 进制数字系统.有效范围是 2-36,默认值为 2.- 填充 (padding)int, optional
在左侧填充的零的个数.默认为 0 (不填充).
- 返回:
- outstr
number在 base 进制系统中的字符串表示.
参见
binary_reprbase_repr的更快版本,用于 2 进制.
示例
>>> import numpy as np >>> np.base_repr(5) '101' >>> np.base_repr(6, 5) '11' >>> np.base_repr(7, base=5, padding=3) '00012'
>>> np.base_repr(10, base=16) 'A' >>> np.base_repr(32, base=16) '20'