Python numpy.defchararray.multiply()

Python numpy.defchararray.multiply()

numpy.core.defchararray.multiply(arr, n) 。连接字符串的’n’次元素。

参数:
arr :类似数组或字符串。
n :[array-like]我们要连接的次数。

返回值 :串联字符串的’n’倍元素。

代码 #1:

# Python Program illustrating 
# numpy.char.multiply() method 
import numpy as np 
  
arr1 = ['eAAAa', 'ttttds', 'AAt']
arr2 = ['11sf', 'sdsf2', '1111f2']
  
print ("\narr1 : ", arr1)
print ("\narr2 : ", arr2)
  
print ("\narr1 : ", np.char.multiply(arr1, 2))
  
# Separate multiplication
print ("\narr1 : ", np.char.multiply(arr1, [2, 4, 3]))
print ("\narr2 : ", np.char.multiply(arr2, 3))

输出:

arr1 :  ['eAAAa', 'ttttds', 'AAt']

arr2 :  ['11sf', 'sdsf2', '1111f2']

arr1 :  ['eAAAaeAAAa' 'ttttdsttttds' 'AAtAAt']

arr1 :  ['eAAAaeAAAa' 'ttttdsttttdsttttdsttttds' 'AAtAAtAAt']

arr2 :  ['11sf11sf11sf' 'sdsf2sdsf2sdsf2' '1111f21111f21111f2']

代码 #2:

# Python Program illustrating 
# numpy.char.multiply() method 
import numpy as np 
  
arr1 = 'This is geeks '
arr2 = 'for geeks '
  
print ("\narr1 : ", np.char.multiply(arr1, 2))
print ("\narr2 : ", np.char.multiply(arr2, 4))

输出:

arr1 :  This is geeks 
arr2 :  for geeks 

arr1 :  This is geeks This is geeks 
arr2 :  for geeks for geeks for geeks for geeks 

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程