[Python] Boolean Or "Mask" Index Arrays filter with numpy
2023-09-14 08:59:17 时间
NumPy Reference: Indexing
Note: The expression a < mean
produces a boolean array, like:
[[False, False, True, False, False, False, True, True, True],
[True, True, False, False, True, True, False, True, True]]
def filter(): a = np.array([ (20,20,10,23,26,32,10,5,0), (0,2,50,20,0,1,28,5,0) ]) mean = a.mean() print("mean",mean) #14.0 print(a[a<mean]) #[10 10 5 0 0 2 0 1 5 0] # replace all which value which is less than mean value a[a<mean]=mean print(a) """ [[20 20 14 23 26 32 14 14 14] [14 14 50 20 14 14 28 14 14]] """ if __name__ == "__main__": filter()
相关文章
- 第三百六十五节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的基本查询
- 第三百六十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的mapping映射管理
- [Python] Optimizing code with numpy intersect1d, and Set
- Python编程语言学习:基于python各种库(matplotlib、Image)利用多种方法展示图片或进行图片可视化之详细攻略
- Python:利用python语言实现18位身份证号码和15位身份证号码相互转换
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)
- Python编程语言学习:python的列表的特殊应用之一行命令实现if判断中的两类判断
- Python:利用python语言绘制多个子图经典案例、代码实现之详细攻略
- Python语言学习之双下划线那些事:python和双下划线使用方法之详细攻略
- 100天精通Python(可视化篇)——第81天:matplotlib绘制不同种类炫酷饼图参数说明+代码实战(自定义、百分比、多个子图、圆环、嵌套饼图)
- 已解决2.Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and wi
- python共享内存和分布式实现异步加载数据
- 从零开始学python | 什么是Python JSON?
- Python实现ALO蚁狮优化算法优化支持向量机分类模型(SVC算法)项目实战
- 【华为OD机试Python实现】HJ20 密码验证合格程序(中等)
- python数据分析-numpy 矩阵操作
- Python实战:使用re正则库匹配url中的id信息
- Python编程:pillow对图像的简单处理
- python 常见脚本
- Python学习笔记(八)—— 使用dict和set
- python 爬虫之requests模块设置代理
- 【Python-Numpy】numpy.random.binomial()的解析与使用
- 【Leetcode刷题Python】只出现一次的数字 II
- 【python】Python实现网络爬虫demo实例
- Python爬虫教程(非常详细)从零基础入门到精通,看完这一篇就够了
- python将MP3转wave转成numpy
- Python(17):Numpy之array数组的排序
- leetcode -python 三数之和原创