zoukankan      html  css  js  c++  java
  • Python Numpy模块函数np.c_和np.r_

        np.r_:是按列连接两个矩阵,就是把两矩阵上下相加,要求列数相等,类似于pandas中的concat()。

        np.c_:是按行连接两个矩阵,就是把两矩阵左右相加,要求行数相等,类似于pandas中的merge()。

      

    import numpy as np
    a = np.array([1, 2, 3])
    b = np.array([4, 5, 6])
    c = np.c_[a,b]
    
    print(np.r_[a,b])
    print('
    ')
    print(c)
    print('
    ')
    print(np.c_[c,a])
    ################################
    结果:
    [1 2 3 4 5 6]
    
    
    [[1 4]
     [2 5]
     [3 6]]
    
    
    [[1 4 1]
     [2 5 2]
     [3 6 3]]

     其它函数

    a = np.arange( 10, 30, 5 )
    print(a)
    # [10 15 20 25]
    
    
    a = np.arange(15).reshape(3, 5)
    print(a)
    # [[ 0  1  2  3  4]
    #  [ 5  6  7  8  9]
    #  [10 11 12 13 14]]
    
    a = np.array([1,2,3,4,5,6,7,8,9]).reshape(3,3)
    print(a)
    # [[1 2 3]
    #  [4 5 6]
    #  [7 8 9]]
    
    a = np.zeros((3,4))
    print(a)
    # [[0. 0. 0. 0.]
    #  [0. 0. 0. 0.]
    #  [0. 0. 0. 0.]]
    
    a = np.linspace( 0, 2, 9 )
    print(a)
    # [0.   0.25 0.5  0.75 1.   1.25 1.5  1.75 2.  ]
    
    a = np.ones(3, dtype=np.int32)
    print(a)
    # [1 1 1]
    
    a = np.ones((2,3), dtype=int)
    print(a)
    # [[1 1 1]
    #  [1 1 1]]
  • 相关阅读:
    Commander Nodejs 命令行接口
    数据库集群 ---续集
    数据库集群
    实时查看linux下的日志
    自动化测试
    python中list和dict
    super与this的用法
    数据类型
    父类调用子类方法
    子类调用父类方法
  • 原文地址:https://www.cnblogs.com/shaosks/p/9890787.html
Copyright © 2011-2022 走看看