numpy 数组增加列,增加行的函数:column_stack,row_stack,删除行或列的函数,delete

 1 def fun_ndarray():
 2     a = [[1,2,7],
 3          [-6,-2,-3],
 4          [-4,-8,-55]
 5          ]
 6     b = [3,5,6]
 7     a = np.array(a)
 8     b = np.array(b)
 9     a_b_column = np.column_stack((a,b))#左右根据列拼接
10     a_b_row = np.row_stack((a,b))#上下按照行拼接
11     print('a_b_column')
12     print(a_b_column)
13     print('a_b_row')
14     print(a_b_row)

结果:

note:

column_stack,row_stack函数参数是一个元组

np.delete():删除行或列

data = np.delete(data,3,axis=1) # 删除第四列
原文地址:https://www.cnblogs.com/shuangcao/p/11380964.html