zoukankan      html  css  js  c++  java
  • count(),列表推导式,transpose()

    count()函数 列表推导式

    In [85]:
    #统计列表每个元素中指定单词出现的个数
    words=['apple','pare','banana','and','peach','Anda']
    for word in words:
        print(word.lower().count('a'))  #lower()识别大小写
    1
    1
    3
    1
    1
    2
    
    In [86]:
     [word for word in words if word.lower().count('a')>=2]
     
     
    Out[86]:
    ['banana', 'Anda']
    In [69]:
    strings=['a','bv','tit','apple','ctr']
    [x.title() for x in strings if len(x)>2]
     
     
    Out[69]:
    ['Tit', 'Apple', 'Ctr']
    In [74]:
    list(map(len,strings))
      
    Out[74]:
    [1, 2, 3, 5, 3]
     

    transpose() 转置

    In [88]:
    import numpy as np
    three=np.arange(18).reshape(2,3,3)
     
    In [89]:
    three
     
    Out[89]:
    array([[[ 0,  1,  2],
            [ 3,  4,  5],
            [ 6,  7,  8]],
    
           [[ 9, 10, 11],
            [12, 13, 14],
            [15, 16, 17]]])
    In [97]:
     
    three.transpose(2,1,0)
    Out[97]:
    array([[[ 0,  9],
            [ 3, 12],
            [ 6, 15]],
    
           [[ 1, 10],
            [ 4, 13],
            [ 7, 16]],
    
           [[ 2, 11],
            [ 5, 14],
            [ 8, 17]]])
     
  • 相关阅读:
    react-umi 光速上手
    vue 和 react 的区别
    SP12323 NAKANJ
    UVA439 骑士的移动
    NOI 2020 Vlog
    二叉查找树
    可持久化线段树(主席树)
    权值线段树
    YNOI2020 游记
    《四月是你的谎言》语录
  • 原文地址:https://www.cnblogs.com/liyun1/p/11261867.html
Copyright © 2011-2022 走看看