zoukankan      html  css  js  c++  java
  • Numpy学习---字符串处理

    学习时,借鉴正常处理字符串的几个基本函数,较容易掌握

    1.add()

    import numpy as np
    #caes1: strings
    print(np.char.add('multiple	'v,'alue'))  #相接不留痕
    # multiple value 
    #case2: array
    print(np.char.add(['aaa','bbb'],['ccc','ddd'])) #对应元素相接
    #  ['aaaccc' 'bbbddd']
    View Code

    2.multiply()

    >>> print(np.char.multiply('blog',4))
    blogblogblogblog

    3.center()

    >>> print(np.char.center('cumt',20,fillchar='@'))
    @@@@@@@@cumt@@@@@@@@

    4.capitalize()

    >>> print(np.char.capitalize('cumt'))
    Cumt

    5.title()

    >>> print(np.char.title('cumt is china university of mining and technology'))
    Cumt Is China University Of Mining And Technology
    

    capitalize 与 title 区别在于:title会将每个单词的首字母大写

    6.lower() 和 upper()

    >>> print(np.char.lower('I Like Data'))
    i like data
    >>> print(np.char.upper('i like data'))
    I LIKE DATA

    7.split()

    #默认分隔符为空格
    >>> print(np.char.split(' Central Limit Therom'))
    ['Central', 'Limit', 'Therom']
    #指定分隔符
    >>> print(np.char.split('Central,limit,therom',','))
    ['Central', 'limit', 'therom']

    7.splitlines()

    #分割换行符
    >>> print(np.char.splitlines('Central Limit
    Therom'))
    ['Central Limit', 'Therom']
    >>> print(np.char.splitlines('Central
    Limit Therom'))
    ['Central', 'Limit Therom']

    8.strip()

    >>> print(np.char.strip('Central limit therom','c')) #区别大小写
    Central limit therom
    >>> print(np.char.strip('Central limit therom','m'))
    Central limit thero

    8.join()

    >>> print(np.char.join('@','cumt'))
    c@u@m@t
    >>> print(np.char.join(['@','¥'],['cumt','rmb']))
    ['c@u@m@t' 'r¥m¥b']
    

    10.replace()

    >>> print(np.char.replace('bar-plot','bar','scattter'))
    scattter-plot

    11.strip()

    >>> print(np.char.strip('Central limit therom','c'))
    Central limit therom
    >>> print(np.char.strip('Central limit therom','m'))
    Central limit thero
    >>> print(np.char.strip(' limit '))
    limit
    >>> print(np.char.strip(['Central','domain','function','notation','node'],'n'))
    ['Central' 'domai' 'functio' 'otatio' 'ode']
  • 相关阅读:
    学习 TList 类的实现[8]
    System.SetString 获取字符串
    System.Odd 判断一个整数是不是奇数
    问与答[2008331]
    System.Val 将字符串转换为数字
    事件自调用 回复 maxcool 的问题
    JS操作select相关方法:新增 修改 删除 选中 清空 判断存在 等
    自由人生 从容生活
    [引]智能设备开发演练:创建用于设备的 Windows 窗体应用程序
    gentle做的分页控件
  • 原文地址:https://www.cnblogs.com/bigriverx/p/13672270.html
Copyright © 2011-2022 走看看