numpy.delete删除一列或多列的方法


Posted in Python onApril 03, 2018

基础介绍:

numpy.delete
numpy.delete(arr, obj, axis=None)[source]
 Return a new array with sub-arrays along an axis deleted. For a one dimensional array, this returns those entries not returned by arr[obj].
 Parameters:	
 arr : array_like
  Input array.
 obj : slice, int or array of ints
  Indicate which sub-arrays to remove.
 axis : int, optional
  The axis along which to delete the subarray defined by obj. If axis is None, obj is applied to the flattened array.
 Returns:	
 out : ndarray
  A copy of arr with the elements specified by obj removed. Note that delete does not occur in-place. If axis is None, out is a flattened array.

示例:

1.删除一列

>>> dataset=[[1,2,3],[2,3,4],[4,5,6]] 
>>> import numpy as np 
>>> dataset = np.delete(dataset, -1, axis=1) 
>>> dataset 
array([[1, 2], 
  [2, 3], 
  [4, 5]])

2.删除多列

arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) 
np.delete(arr, [1,2], axis=1) 
array([[ 1, 4], 
  [ 5, 8], 
  [ 9, 12]])

以上这篇numpy.delete删除一列或多列的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python基于列表模拟堆栈和队列功能示例
Jan 05 Python
numpy.transpose对三维数组的转置方法
Apr 17 Python
Python随机函数random()使用方法小结
Apr 29 Python
Python 使用类写装饰器的小技巧
Sep 30 Python
Python 将Matrix、Dict保存到文件的方法
Oct 30 Python
python 运用Django 开发后台接口的实例
Dec 11 Python
Python爬虫beautifulsoup4常用的解析方法总结
Feb 25 Python
python PyAutoGUI 模拟鼠标键盘操作和截屏功能
Aug 04 Python
Django模板导入母版继承和自定义返回Html片段过程解析
Sep 18 Python
Python 读取 YUV(NV12) 视频文件实例
Dec 09 Python
np.random.seed() 的使用详解
Jan 14 Python
python3.5的包存放的具体路径
Aug 16 Python
取numpy数组的某几行某几列方法
Apr 03 #Python
Python numpy 提取矩阵的某一行或某一列的实例
Apr 03 #Python
python3安装pip3(install pip3 for python 3.x)
Apr 03 #Python
Win7 64位下python3.6.5安装配置图文教程
Oct 27 #Python
windows10下python3.5 pip3安装图文教程
Apr 02 #Python
浅谈python numpy中nonzero()的用法
Apr 02 #Python
Python数据处理numpy.median的实例讲解
Apr 02 #Python
You might like
队列在编程中的实际应用(php)
2010/09/04 PHP
PHP基于openssl实现的非对称加密操作示例
2019/01/11 PHP
Aliyun Linux 编译安装 php7.3 tengine2.3.2 mysql8.0 redis5的过程详解
2020/10/20 PHP
JavaScript全局函数使用简单说明
2011/03/11 Javascript
JQuery为textarea添加maxlength属性并且兼容IE
2013/04/25 Javascript
Javascript封装DOMContentLoaded事件实例
2014/06/12 Javascript
javascript数组遍历for与for in区别详解
2014/12/04 Javascript
基于JQuery的$.ajax方法进行异步请求导致页面闪烁的解决办法
2016/05/10 Javascript
ajax实现动态下拉框示例
2017/01/10 Javascript
vue使用Axios做ajax请求详解
2017/06/07 Javascript
vue.js 添加 fastclick的支持方法
2018/08/28 Javascript
AngularJS 事件发布机制
2018/08/28 Javascript
vue插槽slot的理解和使用方法
2019/04/03 Javascript
JS实现的简单tab切换功能完整示例
2019/06/20 Javascript
解决vue中使用less/sass及使用中遇到无效的问题
2020/10/24 Javascript
[02:36]DOTA2混沌骑士 英雄基础教程
2013/11/26 DOTA
用Python编写一个国际象棋AI程序
2014/11/28 Python
python根据出生日期获得年龄的方法
2015/03/31 Python
Python装饰器原理与用法分析
2018/04/30 Python
Python脚本按照当前日期创建多级目录
2019/03/01 Python
Python字符串的常见操作实例小结
2019/04/08 Python
python发送多人邮件没有展示收件人问题的解决方法
2019/06/21 Python
Python交互式图形编程的实现
2019/07/25 Python
Flask框架钩子函数功能与用法分析
2019/08/02 Python
详解从Django Allauth中进行登录改造小结
2019/12/18 Python
python制作抽奖程序代码详解
2021/01/15 Python
澳大利亚连衣裙和女装在线:Esther
2017/11/11 全球购物
俄罗斯韩国化妆品网上商店:Cosmasi.ru
2019/10/31 全球购物
西部世纪面试题
2014/12/05 面试题
煤矿安全演讲稿
2014/05/09 职场文书
党的作风建设心得体会
2014/10/22 职场文书
学生会工作感言
2015/08/07 职场文书
2016学习依法治国心得体会
2016/01/15 职场文书
Python pygame实现中国象棋单机版源码
2021/06/20 Python
nginx作grpc的反向代理踩坑总结
2021/07/07 Servers
浅谈spring boot使用thymeleaf版本的问题
2021/08/04 Java/Android