numpy.strings.mod#
- strings.mod(a, values)[source]#
傳回 (a % i),即 Python 2.6 之前的字串格式化(插值),針對 str 或 unicode 的類陣列配對逐元素執行。
- 參數:
- a類陣列,具有 np.bytes_ 或 np.str_ dtype
- values值的類陣列
這些值將逐元素插值到字串中。
- 傳回值:
- outndarray
輸出陣列,其 dtype 為
StringDType
、bytes_
或str_
,取決於輸入類型
範例
>>> 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')