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']
  • 相关阅读:
    2015.07-2015.08
    the last lecture
    强化的单例属性_Effective Java
    Socket通信客户端设计(Java)
    静态工场方法代替构造器
    如何控制Java中的线程,总结了3种方法...
    如何快速转型,比如C#...to...Java
    C#中var和dynamic
    How to use the Visual Studio
    mark blog
  • 原文地址:https://www.cnblogs.com/bigriverx/p/13672270.html
Copyright © 2011-2022 走看看