numpy.char.mod#
- char.mod(a, values)[原始碼]#
傳回 (a % i),即 Python 2.6 之前的字串格式化(插值),針對 str 或 unicode 的 array_like 成對元素逐個執行。
- 參數:
- aarray_like,具有 np.bytes_ 或 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')