我刚刚开始使用 numpy。在进行分类时我遇到了np.ndarray.sum(-1)。
像这样的代码
rand_arr = np.random.rand(10, 2)
differences = rand_arr[:, np.newaxis, :] - rand_arr[np.newaxis, :, :]
Run Code Online (Sandbox Code Playgroud)
所以差异是一个 3-D 矩阵shape (10,10,2)
现在他们正在使用这个命令
difference.sum(-1) # this will convert the 3-D matrix into 2-D matrix of shape (10,10)
那么这.sum(-1)到底意味着什么呢?