📜  numpy字符串操作 |标题()函数

📅  最后修改于: 2022-05-13 01:54:28.530000             🧑  作者: Mango

numpy字符串操作 |标题()函数

numpy.core.defchararray.title(arr)函数用于返回字符串或 unicode 的元素级标题大小写版本。标题大小写单词以大写字符开头,所有剩余的大小写字符均为小写。

代码#1:

# Python Program explaining
# numpy.char.title() function 
  
import numpy as geek 
  
  
in_arr = geek.array(['p4q r', '4q rp', 'q rp4', 'rp4q'])
print ("input array : ", in_arr)
  
out_arr = geek.char.title(in_arr)
print ("output titled array :", out_arr)
输出:
input array :  ['p4q r' '4q rp' 'q rp4' 'rp4q']
output titled array : ['P4Q R' '4Q Rp' 'Q Rp4' 'Rp4Q']


代码#2:

# Python Program explaining
# numpy.char.title() function 
  
import numpy as geek 
  
  
in_arr = geek.array(['geeks', 'for', 'geeks'])
  
print ("input array : ", in_arr)
  
out_arr = geek.char.title(in_arr)
print ("output titled array :", out_arr )
输出:
input array :  ['geeks' 'for' 'geeks']
output titled array : ['Geeks' 'For' 'Geeks']