numpy.char.multiply#
- char.multiply(a, i)[原始碼]#
傳回 (a * i),即字串重複串聯,逐元素運算。
i
中小於 0 的值會被視為 0 (產生空字串)。- 參數:
- aarray_like,具有 np.bytes_ 或 np.str_ dtype
- iarray_like,具有任何整數 dtype
- 傳回值:
- outndarray
字串或 unicode 的輸出陣列,取決於輸入類型
註解
這是 np.strings.multiply 的輕薄封裝器,當
i
不是整數時會引發 ValueError。它僅為了向後相容性而存在。範例
>>> import numpy as np >>> a = np.array(["a", "b", "c"]) >>> np.strings.multiply(a, 3) array(['aaa', 'bbb', 'ccc'], dtype='<U3') >>> i = np.array([1, 2, 3]) >>> np.strings.multiply(a, i) array(['a', 'bb', 'ccc'], dtype='<U3') >>> np.strings.multiply(np.array(['a']), i) array(['a', 'aa', 'aaa'], dtype='<U3') >>> a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3)) >>> np.strings.multiply(a, 3) array([['aaa', 'bbb', 'ccc'], ['ddd', 'eee', 'fff']], dtype='<U3') >>> np.strings.multiply(a, i) array([['a', 'bb', 'ccc'], ['d', 'ee', 'fff']], dtype='<U3')