当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.defchararray.add()用法及代码示例


numpy.core.defchararray.add(arr1, arr2)以元素方式连接两个字符串。

参数:
arr1 : array-like or string.
arr2 : array-like or string.

返回: Concatenates String.



代码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 


相关用法


注:本文由纯净天空筛选整理自Mohit Gupta_OMG 大神的英文原创作品 numpy.defchararray.add() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。