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']
  • 相关阅读:
    那些容易忽略的事4-(正则表达式反向引用 )
    那些容易忽略的事3-(变量提升和函数提升)
    那些容易忽略的事(2)
    那些容易忽略的事(1) -变量与运算符+
    call()与apply()传参需要注意的一点
    CSS凹型导航按钮
    动态的99乘法表
    js中的for-of循环遍历数组
    交换2个变量的值
    gl.disableVertexArray P77 关闭location指定的attribute变量
  • 原文地址:https://www.cnblogs.com/bigriverx/p/13672270.html
Copyright © 2011-2022 走看看