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


Python numpy.defchararray.capitalize()用法及代碼示例


numpy.core.defchararray.multiply(arr,n):按元素大小寫將字符串的首字母大寫。

參數:
arr : array-like or string.

返回: Capitalized first letter of the string.



代碼1:

# Python Program illustrating  
# numpy.char.capitalize() method  
import numpy as np  
  
arr1 = ['eAAAaeAAAa', 'ttttdsttttds', 'AAtAAt'] 
arr2 = ['11sf', 'sdsf2', '1111f2'] 
  
print ("arr1:", arr1) 
print ("arr2:", arr2) 
  
Print("\nArrays after using capitalize():") 
print ("\narr1:", np.char.capitalize(arr1)) 
print ("arr2:", np.char.capitalize(arr2))

輸出:

arr1: ['eAAAaeAAAa', 'ttttdsttttds', 'AAtAAt']
arr2: ['11sf', 'sdsf2', '1111f2']

Arrays after using capitalize():
arr1: ['Eaaaaeaaaa' 'Ttttdsttttds' 'Aataat']
arr2: ['11sf' 'Sdsf2' '1111f2']


代碼2:

# Python Program illustrating  
# numpy.char.capitalize() method  
import numpy as np  
  
arr1 = 'this is geeks '
arr2 = 'for geeks '
  
print ("arr1:", arr1) 
print ("arr2:", arr2) 
  
Print("\nArrays after using capitalize():") 
print ("\narr1:", np.char.capitalize(arr1)) 
print ("arr2:", np.char.capitalize(arr2))

輸出:

arr1: this is geeks 
arr2: for geeks 

Arrays after using capitalize():
arr1: This is geeks 
arr2: For geeks  


相關用法


注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 numpy.defchararray.capitalize() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。