numpy.char.mod#

char.mod(a, values)[源代码]#

返回 (a % i),即 pre-Python 2.6 字符串格式(插值),针对 str 或 unicode 的 array_likes 逐元素执行.

参数:
a : array_like, 具有 np.bytes_np.str_ dtypearray_like, with np.bytes_ or np.str_ dtype
values值的 array_like

这些值将被逐元素地插入到字符串中.

返回:
outndarray

StringDType , bytes_str_ dtype 的输出数组,具体取决于输入类型

示例

>>> import numpy as np
>>> a = np.array(["NumPy is a %s library"])
>>> np.strings.mod(a, values=["Python"])
array(['NumPy is a Python library'], dtype='<U25')
>>> a = np.array([b'%d bytes', b'%d bits'])
>>> values = np.array([8, 64])
>>> np.strings.mod(a, values)
array([b'8 bytes', b'64 bits'], dtype='|S7')