numpy.char.multiply#
- char.multiply(a, i)[源代码]#
返回 (a * i),即字符串多重连接,逐个元素执行.
i中小于 0 的值被视为 0(这将产生一个空字符串).- 参数:
- a : array_like,具有 np.bytes_ 或 np.str_ dtypearray_like, 具有
- i类数组对象,具有任何整数dtype
- 返回:
- outndarray
str 或 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')