问题
I have an numpy ndarray like below:
[[1 9 1 1]
[9 3 1 1]
[1 9 9 1]
[8 2 4 7]]
I want to add last 2 columns values to get below result
[[1 9 2]
[9 3 2]
[1 9 10]
[8 2 11]]
回答1:
Sum, then drop the last column
myArray[:, -2] = myArray[:,-2] + myArray[:,-1]
myArray = myArray[:,:-1]
来源:https://stackoverflow.com/questions/61092371/how-to-add-2-columns-in-numpy-ndarray