当前位置:网站首页>np. Understanding of axis in concatenate

np. Understanding of axis in concatenate

2022-06-13 01:06:00 Thinking and Practice

Parameters in official documents  

concatenate(...)
    concatenate((a1, a2, ...), axis=0)

    Join a sequence of arrays along an existing axis.

    Parameters
    ----------
    a1, a2, ... : sequence of array_like
        The arrays must have the same shape, except in the dimension
        corresponding to `axis` (the first, by default).
    axis : int, optional
        The axis along which the arrays will be joined.  Default is 0.

    Return

array.shape,axis=0 Is to operate on the first dimension ,

axis=1 That's right 2 Operate on multiple dimensions ,

axis=2 That's right 3 Operate on multiple dimensions , And so on …

The first dimension is along x Splice in the direction , That is, the matrix is spliced up and down ; The second dimension is along y Splice in the direction , That is, the matrix and the matrix are spliced left and right ; The third dimension is along z Splice in the direction , That is, to put the matrix and the matrix together .(x,y The direction is the normal axis direction )

Be careful : When splicing, you must pay attention to the dimension , like axis=0, To splice up and down , Then the number of columns of the two matrices must be the same ;axis=1 The same number of lines ;axis=2 That is, the number of rows and columns are the same .
————————————————
Copyright notice : This paper is about CSDN Blogger 「ly_ljs_521」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/ly_ljs_521/article/details/123204684

Example

a = np.array([[1, 2], [3, 4]]) 
b = np.array([[5, 6]])
np.concatenate((a, b), axis=0)  #  there axis=0 Is merged by rows 

array([[1, 2],
       [3, 4],
       [5, 6]])

a = np.array([[1, 2], [3, 4]]) 
b = np.array([[5, 6]])
np.concatenate((a, b.T), axis=1)  #  there axis=1 Is merged by column 

array([[1, 2, 5],
       [3, 4, 6]])

Reference material

In depth learning concatenate Use _alxe_made The blog of -CSDN Blog _concatenate

np.concatenate in axis The understanding of the _ly_ljs_521 The blog of -CSDN Blog _concatenate Of axis

np.concatenate() Instructions _Tchunren The blog of -CSDN Blog _np.concat

原网站

版权声明
本文为[Thinking and Practice]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130100484145.html