當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。