用python写一个删除ndarray中第五列的程序,在ndarray为空时也可用
时间: 2023-06-06 09:06:37 浏览: 38
好的,可以用以下代码实现:
```python
import numpy as np
def delete_fifth_column(arr):
if arr.size == 0:
return arr
else:
return np.delete(arr, 4, axis=1)
```
其中,`arr`表示传入的`ndarray`,`np.delete()`函数用于删除指定轴的元素。判断数组是否为空可以使用`arr.size == 0`。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)