如何在Python 3中按索引从numpy数组中删除元素?

时间:2019-06-05 06:11:47

标签: python-3.x numpy

我想通过索引从numpy数组中删除一个元素。

命令

SELECT D.Name AS Department, E.Name AS Employee, E.Salary
FROM Employee AS E LEFT JOIN Department AS D ON E.DepartmentId = D.id
WHERE (E.Salary = (SELECT MAX(X.Salary) FROM Employee AS X WHERE (X.DepartmentId = E.DepartmentId)));

SELECT D.Name AS Department, E.Name AS Employee, E.Salary
FROM Employee AS E LEFT JOIN Department AS D ON E.DepartmentId = D.id
INNER JOIN (SELECT DepartmentId, MAX(Salary) AS MaxSalary FROM Employee GROUP BY DepartmentId) AS X ON E.DepartmentId = X.DepartmentId AND E.Salary = X.MaxSalary;

上面的代码引发错误,提示arr = np.linspace(-5,5,10) del arr[0] 。 使用cannot delete array elements也不起作用。我该怎么办?

1 个答案:

答案 0 :(得分:1)

您应该使用np.delete

arr = np.linspace(-5,5,10)
arr = np.delete(arr, 0)