Python numpy.defchararray.add()

Python numpy.defchararray.add()

numpy.core.defchararray.add(arr1, arr2) :将两个字符串按元素串联起来。

参数:
arr1 :类似数组或字符串。
arr2 :类似数组或字符串。

返回值 :串联字符串。

代码 #1:

# Python Program illustrating 
# numpy.char.add() method 
import numpy as np 
  
arr1 = ['vdteteAAAa', 'AAAttttds', 'AAaxtt']
arr2 = ['1111sfdsf', '1111111sdsf2', '1111111sfsf2']
  
print ("\narr1 : ", arr1)
print ("\narr2 : ", arr2)
  
print ("\narr1 + arr2\n", np.char.add(arr1, arr2))
print ("\narr2 + arr1\n", np.char.add(arr2, arr1))

输出:

arr1 :  ['vdteteAAAa', 'AAAttttds', 'AAaxtt']

arr2 :  ['1111sfdsf', '1111111sdsf2', '1111111sfsf2']

arr1 + arr2
 ['vdteteAAAa1111sfdsf' 'AAAttttds1111111sdsf2' 'AAaxtt1111111sfsf2']

arr2 + arr1
 ['1111sfdsfvdteteAAAa' '1111111sdsf2AAAttttds' '1111111sfsf2AAaxtt']

代码 #2:

# Python Program illustrating 
# numpy.char.add() method 
import numpy as np 
  
arr1 = 'This is geeks '
arr2 = 'for geeks '
  
print ("\narr1 + arr2\n", np.char.add(arr1, arr2))
print ("\narr2 + arr1\n", np.char.add(arr2, arr1))

输出:

arr1 + arr2
 This is geeks for geeks 

arr2 + arr1
 for geeks This is geeks 

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程