zoukankan      html  css  js  c++  java
  • numpy.concatenate

    import numpy as np
    
    a = np.array([[1, 2], [3, 4]])
    
    a.shape
    Out[3]: (2, 2)
    
    b = np.array([[5, 6]])
    
    b.shape
    Out[5]: (1, 2)
    
    np.concatenate((a, b))
    Out[6]: 
    array([[1, 2],
           [3, 4],
           [5, 6]])
    
    c= np.concatenate((a, b))
    
    c.shape
    Out[8]: (3, 2)
    
    d = np.concatenate((a, b), axis=0)
    
    d.shape
    Out[10]: (3, 2)
    
    e = np.concatenate((a, b), axis=1)
    Traceback (most recent call last):
    
      File "<ipython-input-11-05a280a2cb02>", line 1, in <module>
        e = np.concatenate((a, b), axis=1)
    
    ValueError: all the input array dimensions except for the concatenation axis must match exactly
    
    
    e = np.concatenate((a, b.T), axis=1)
    
    e.shape
    Out[13]: (2, 3)

    import numpy as np

    a = np.array([[1, 2], [3, 4]])

    a.shape
    Out[3]: (2, 2)

    b = np.array([[5, 6]])

    b.shape
    Out[5]: (1, 2)

    np.concatenate((a, b))
    Out[6]:
    array([[1, 2],
    [3, 4],
    [5, 6]])

    c= np.concatenate((a, b))

    c.shape
    Out[8]: (3, 2)

    d = np.concatenate((a, b), axis=0)

    d.shape
    Out[10]: (3, 2)

    e = np.concatenate((a, b), axis=1)
    Traceback (most recent call last):

    File "<ipython-input-11-05a280a2cb02>", line 1, in <module>
    e = np.concatenate((a, b), axis=1)

    ValueError: all the input array dimensions except for the concatenation axis must match exactly


    e = np.concatenate((a, b.T), axis=1)

    e.shape
    Out[13]: (2, 3)

    e
    Out[14]:
    array([[1, 2, 5],
    [3, 4, 6]])

  • 相关阅读:
    vue--常用指令
    vue--npm的使用
    DRF--认证和权限
    DRF--路由组件和版本控制
    nginx--代理和负载均衡
    DRF--重写views
    DRF--ModelSerializer和时间格式化
    DRF--验证器
    DRF--序列化
    DRF--介绍和安装
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/5763120.html
Copyright © 2011-2022 走看看