这篇文章主要介绍numpy中np.column_stack()和np.row_stack()怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
在numpy库中,对于矩阵的合并操作用两种方法:
行合并:np.row_stack()
列合并:np.column_stack()
具体操作见下面的程序:
>>> import numpy as np >>> a=np.arange(16).reshape(4,-1) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) >>> b=np.arange(16,32).reshape(4,-1) >>> b array([[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]]) >>> test=np.row_stack((a,b))#行合并 >>> test array([[ 0, 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]]) >>> test=np.column_stack((a,b))#列合并 >>> test array([[ 0, 1, 2, 3, 16, 17, 18, 19], [ 4, 5, 6, 7, 20, 21, 22, 23], [ 8, 9, 10, 11, 24, 25, 26, 27], [12, 13, 14, 15, 28, 29, 30, 31]]) >>>
以上是“numpy中np.column_stack()和np.row_stack()怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/223758.html