python - 在 Python 中从数组中删除一些元素

标签 python python-2.7 python-3.x

我还有一个问题,我在 Python 中有这个数组:

import numpy as np

A = np.zeros((5));
A[0] = 2;
A[1] = 3;
A[2] = 7;
A[3] = 1;
A[4] = 8;

我想做的是删除 A[i] for i from 2 to 4 也就是说我正在寻找这样的命令:

A = np.delete(A, [2:4]) 但不幸的是它不起作用,因为我在这里看到了文档:http://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html但这对我没有帮助。

感谢您的帮助!

最佳答案

如果你想要从 numpy 数组中删除位置,你可以使用:

np.delete(A, slice(2,5))  # note that the interval is inclusive, exclusive [2, 5)

关于python - 在 Python 中从数组中删除一些元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38770911/

相关文章:

python - Django Rest 框架 JWT "Authentication credentials were not provided."}

python - Xlsx 编写器 : Writing strings with multiple format in a single cell

python - 如何使 pyserial 环回工作?

Python + 禁用打印输出,无法取回

Python 数据帧 : Seperate rows based on custom condition?

python - 在 OS X 上安装 python 2 的最佳方法是什么?

python - 在 python 中基于列表理解的条件跳过元素

python - 无法在 Windows 10 collect2.exe 错误上使用 Python27 MingW 安装 leven 包

python - 如何使用 python3 将 CIDR 转换为 IP 范围?

python - 我如何在python中将相同的列表对象分配给两个不同的变量名?