[Python] Boolean Or "Mask" Index Arrays filter with numpy
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] Boolean Or "Mask" Index Arrays filter with numpy的更多相关文章
- [python基础知识]python内置函数map/reduce/filter
python内置函数map/reduce/filter 这三个函数用的顺手了,很cool. filter()函数:filter函数相当于过滤,调用一个bool_func(只返回bool类型数据的方法) ...
- Python高阶函数_map/reduce/filter函数
本篇将开始介绍python高阶函数map/reduce/filter的用法,更多内容请参考:Python学习指南 map/reduce Python内建了map()和reduce()函数. 如果你读过 ...
- python. pandas(series,dataframe,index) method test
python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as ...
- 全面了解Python中的特殊语法:filter、map、reduce、lambda。
这篇文章主要介绍了Python中的特殊语法:filter.map.reduce.lambda介绍,本文分别对这个特殊语法给出了代码实例,需要的朋友可以参考下filter(function, seque ...
- python中的矩阵、多维数组----numpy
https://docs.scipy.org/doc/numpy-dev/user/quickstart.html (numpy官网一些教程) numpy教程:数组创建 python中的矩阵.多维数 ...
- Python绘图和数值工具:matplotlib 和 numpy下载与使用
安装任何python模块的标准方式是使用标准的python版本,然后添加标准的模块最简单的方法是登陆相应的网站下载程序包. 但是要考虑依赖关系 , 平台和Python版本号. windows一般带有安 ...
- Python【day 14-4】sorted filter map+递归文件夹+二分法查找
def func(x): #普通函数 return x*x ret1 = func(10) #匿名函数 f = lambda x:x*x # 匿名函数写法: 匿名函数名=lambda 参数:返回值 ' ...
- Python【map、reduce、filter】内置函数使用说明(转载)
转自:http://www.blogjava.net/vagasnail/articles/301140.html?opt=admin 介绍下Python 中 map,reduce,和filter 内 ...
- 【转】Python 中map、reduce、filter函数
转自:http://www.blogjava.net/vagasnail/articles/301140.html?opt=admin 介绍下Python 中 map,reduce,和filter 内 ...
随机推荐
- Swift 闭包中 self? 的由来
class UIViewSpringAnimator: SwipeAnimator { // 动画完成的闭包 var completion:((Bool) ->Void)? func addCo ...
- 3ds Max灯光教程之卧室灯光布局实例
对于设计师来说要做好一张好的作品效果图包括很多比如:“造型.色彩搭配.灯光气氛.构图角度等等,上次给大家详细的分析了下产品渲染中摄像机的构图及原理.本期教程来跟大家讨论一下max场景灯光布局问题.以卧 ...
- vue的表格加单选框
https://www.cnblogs.com/calamus/p/8569196.html
- (2016北京集训十)【xsy1529】小Q与进位制 - 分治FFT
题意很简单,就是求这个数... 其实场上我想出了分治fft的正解...然而不会打...然后打了个暴力fft挂了... 没啥好讲的,这题很恶心,卡常卡精度还爆int,要各种优化,有些dalao写的很复杂 ...
- 用centos镜像 制作本地yum源
1.上传iso镜像 2.挂载镜像到相应目录 mkdir /yumiso #创建目录mount -t iso9660 /dev/cdrom/sr0 /yumiso #挂载镜像文件到对应目录 3.备份旧的 ...
- 关于vue事件监听的一个问题
由于新工作需要用vue,所以最近接触最多的也是vue,因为之前一直在用react,所以对于vue上手还是很快的.我也尽量找一些他们两个的异同点,除了多了一些辅助用的方法以外,最大的不同应该是对于组件间 ...
- 转:强制Visual Studio以管理员身份运行
Windows 8的一个既安全又蛋疼之处是UAC的行为被改变了.以往在Windows 7中,只要关闭了UAC,自己的帐号又是本机管理员组的,任何程序都会以管理员身份启动.然而,在Windows 8上, ...
- UILite-MFC/WTL/DirectUI界面库
之前写了UILite库介绍: http://blog.csdn.net/zhangzq86/article/details/9093945 如今UILite库能够使用git訪问了: https://g ...
- Unity渲染
我们先大概了解一下对渲染的优先级有影响的几个因素 1.Camera.Depth 不同相机的深度,在渲染顺序的优先度里面是最高的,Depth越大,渲染的图像越靠前 2.Render.SortingOrd ...
- bzoj1050【HAOI2006】旅行comf
1050: [HAOI2006]旅行comf Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2205 Solved: 1174 [Submit][ ...