Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在numpy ndarray中添加2列?_Python_Python 3.x_Numpy_Numpy Ndarray - Fatal编程技术网

Python 如何在numpy ndarray中添加2列?

Python 如何在numpy ndarray中添加2列?,python,python-3.x,numpy,numpy-ndarray,Python,Python 3.x,Numpy,Numpy Ndarray,我有一个numpy Ndaray,如下所示: [[1 9 1 1] [9 3 1 1] [1 9 9 1] [8 2 4 7]] 我想添加最后两列的值以得到下面的结果 [[1 9 2] [9 3 2] [1 9 10] [8 2 11]] 求和,然后删除最后一列 myArray[:, -2] = myArray[:,-2] + myArray[:,-1] myArray = myArray[:,:-1] 是的,谢谢!

我有一个numpy Ndaray,如下所示:

[[1 9 1 1]
 [9 3 1 1]
 [1 9 9 1]
 [8 2 4 7]]
我想添加最后两列的值以得到下面的结果

[[1 9 2]
 [9 3 2]
 [1 9 10]
 [8 2 11]]

求和,然后删除最后一列

myArray[:, -2] = myArray[:,-2] + myArray[:,-1] 
myArray = myArray[:,:-1]

是的,谢谢!