比如说我有一个3x4(3行4列)的数组
import numpy as np data = [[0,5,0,1], [0,5,0,1], [0,5,0,1]] data = np.array(data) print(data) [[0 5 0 1] [0 5 0 1] [0 5 0 1]]
我想从第2列中减去第4列,并将值放在自己的3x1数组中,如下所示
print(subtraction) [[4] [4] [4]]
在Numpy我该怎么做?
eni9jsuy1#
result = (data[:, 1] - data[:, 3]).reshape((3, 1))
1条答案
按热度按时间eni9jsuy1#