python-numpy

来源:互联网 发布:unity3d ios 红色问号 编辑:程序博客网 时间:2024/05/17 13:43

array增加1行或1列

np.row_stack((nx, row))

np.column_stack((nx, column))

>>> import numpy as np

>>> nx = np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> row = nx[-1]
>>> column = nx[:,-1]
>>> nx1 = np.row_stack((nx, row))
>>> nx2 = np.column_stack((nx, column))
>>> nx
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])
>>> nx1
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9],
       [7, 8, 9]])
>>> nx2
array([[1, 2, 3, 3],
       [4, 5, 6, 6],
       [7, 8, 9, 9]])
>>> 
原创粉丝点击