numpy怎么删除列
时间: 2023-11-19 14:57:23 浏览: 120
如何实现删除numpy.array中的行或列
以下是两种使用numpy删除列的方法:
1. 删除一列
```python
import numpy as np
dataset = np.array([[1,2,3],[2,3,4],[4,5,6]])
dataset = np.delete(dataset, -1, axis=1)
print(dataset)
# 输出:array([[1, 2],
# [2, 3],
# [4, 5]])
```
2. 删除多列
```python
import numpy as np
arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
arr = np.delete(arr, [1,2], axis=1)
print(arr)
# 输出:array([[ 1, 4],
# [ 5, 8],
# [ 9, 12]])
```
阅读全文