美文网首页
如何获取Numpy数据的基本属性

如何获取Numpy数据的基本属性

作者: 游海东 | 来源:发表于2019-11-30 23:29 被阅读0次

    1. 创建数组

    import numpy as np
    
    a1 = np.array([[1,2,3,4,5,6],
                   [7,8,9,10,11,12],
                   [13,14,15,16,17,18],
                   [19,20,21,22,23,24],
                   [25,26,27,28,29,30],
                   [31,32,33,34,35,36]])
    print(a1)
    
    结果:
    [[ 1  2  3  4  5  6]
     [ 7  8  9 10 11 12]
     [13 14 15 16 17 18]
     [19 20 21 22 23 24]
     [25 26 27 28 29 30]
     [31 32 33 34 35 36]]
    

    2. 数组形状

    import numpy as np
    
    a1 = np.array([[1,2,3,4,5,6],
                   [7,8,9,10,11,12],
                   [13,14,15,16,17,18],
                   [19,20,21,22,23,24],
                   [25,26,27,28,29,30],
                   [31,32,33,34,35,36]])
    print(a1.shape)
    
    结果:
    (6, 6)
    

    3. 数组大小

    import numpy as np
    
    a1 = np.array([[1,2,3,4,5,6],
                   [7,8,9,10,11,12],
                   [13,14,15,16,17,18],
                   [19,20,21,22,23,24],
                   [25,26,27,28,29,30],
                   [31,32,33,34,35,36]])
    print(a1.size)
    
    结果
    36
    

    4. 数组维数

    import numpy as np
    
    a1 = np.array([[1,2,3,4,5,6],
                   [7,8,9,10,11,12],
                   [13,14,15,16,17,18],
                   [19,20,21,22,23,24],
                   [25,26,27,28,29,30],
                   [31,32,33,34,35,36]])
    print(a1.ndim)
    
    结果:
    2
    

    相关文章

      网友评论

          本文标题:如何获取Numpy数据的基本属性

          本文链接:https://www.haomeiwen.com/subject/jubawctx.html