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的更多相关文章

  1. [python基础知识]python内置函数map/reduce/filter

    python内置函数map/reduce/filter 这三个函数用的顺手了,很cool. filter()函数:filter函数相当于过滤,调用一个bool_func(只返回bool类型数据的方法) ...

  2. Python高阶函数_map/reduce/filter函数

    本篇将开始介绍python高阶函数map/reduce/filter的用法,更多内容请参考:Python学习指南 map/reduce Python内建了map()和reduce()函数. 如果你读过 ...

  3. python. pandas(series,dataframe,index) method test

    python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as ...

  4. 全面了解Python中的特殊语法:filter、map、reduce、lambda。

    这篇文章主要介绍了Python中的特殊语法:filter.map.reduce.lambda介绍,本文分别对这个特殊语法给出了代码实例,需要的朋友可以参考下filter(function, seque ...

  5. python中的矩阵、多维数组----numpy

    https://docs.scipy.org/doc/numpy-dev/user/quickstart.html  (numpy官网一些教程) numpy教程:数组创建 python中的矩阵.多维数 ...

  6. Python绘图和数值工具:matplotlib 和 numpy下载与使用

    安装任何python模块的标准方式是使用标准的python版本,然后添加标准的模块最简单的方法是登陆相应的网站下载程序包. 但是要考虑依赖关系 , 平台和Python版本号. windows一般带有安 ...

  7. Python【day 14-4】sorted filter map+递归文件夹+二分法查找

    def func(x): #普通函数 return x*x ret1 = func(10) #匿名函数 f = lambda x:x*x # 匿名函数写法: 匿名函数名=lambda 参数:返回值 ' ...

  8. Python【map、reduce、filter】内置函数使用说明(转载)

    转自:http://www.blogjava.net/vagasnail/articles/301140.html?opt=admin 介绍下Python 中 map,reduce,和filter 内 ...

  9. 【转】Python 中map、reduce、filter函数

    转自:http://www.blogjava.net/vagasnail/articles/301140.html?opt=admin 介绍下Python 中 map,reduce,和filter 内 ...

随机推荐

  1. 路飞学城Python-Day11

    [44.函数-生成器] 需求:有一个列表 [0,1,2,3,4,5,6,7,8,9],对这个列表循环+1 li = [0,1,2,3,4,5,6,7,8,9] li = map(lambda x:x+ ...

  2. 【BZOJ4826】【HNOI2017】影魔

    题意: Description 影魔,奈文摩尔,据说有着一个诗人的灵魂.事实上,他吞噬的诗人灵魂早已成千上万.千百年来,他收集了各式各样的灵魂,包括诗人.牧师.帝王.乞丐.奴隶.罪人,当然,还有英雄. ...

  3. C#获取实例运行时间StopWatch类

    在程序运行时有时需要获取某一步骤的操作时间,C#提供的StopWatch类可以很方便的实现这一目的. StopWatch sw=new StopWatch(); sw.Start(); //Do So ...

  4. Spring学习总结(14)——Spring10种常见异常解决方法

    在程序员生涯当中,提到最多的应该就是SSH三大框架了.作为第一大框架的Spring框架,我们经常使用. 然而在使用过程中,遇到过很多的常见异常,我在这里总结一下,大家共勉. 一.找不到配置文件的异常 ...

  5. SJTU 1319. countColors

    题目描写叙述 知道 psypaint 怎么用吗?在巫女系统全面普及的未来世界.非常少人会知道 psypaint 的使用方法. 而身处在公安局作为监视官的朱同学.为了办案须要研究起了 psypaint ...

  6. [React] Optimistic UI update in React using setState()

    In this lesson we will refactor an existing UI update from a typical loading approach to an optimist ...

  7. Unity 相机花式分屏

    花式分屏,顾名思义,可以实现各种不规则几何边界的分屏,是无法直接通过调整相机视口能达到效果的(只能实现矩形的分屏),例如斜对角分屏,几何图形分屏: 假设我们有两个相机,需要上面的斜对角分屏画面,和镜子 ...

  8. OC第二课

    主要内容:实例变量可见度.方法 一.实例变量可见度 public(共同拥有的):实例变量能够在类的内部和外部使用 protected(受保护的.默认的):实例变量仅仅能在该类及其子类中使用 priva ...

  9. iOS开发 - 二维码的生成与读取

    二维码的生成 从iOS7開始集成了二维码的生成和读取功能 此前被广泛使用的zbarsdk眼下不支持64位处理器 生成二维码的步骤: 导入CoreImage框架 通过滤镜CIFilter生成二维码 二维 ...

  10. SharePoint UserProfileService 接口列表 注解

    Remove Leader 除去领袖 Add Leader  加领袖 Get leaders  获得管理员 Get Profile Scherna Get Profile Scherna Names ...