[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 内 ...
随机推荐
- MariaDB GALERA 集群双节点部署
节点1:10.2.2.41 节点2:10.2.2.42 软件: mariadb-galera-10.0.22-linux-x86_64.tar.gz #galera相关参数:(两个节点配置文件类似) ...
- form表单里的坑
我们在写前端表单页面的时候,为了更好的SEO,我们会使用form标签,但是我们经常的情况是:我们并不需要form标签的一些默认事件,比如: 1.form内只有一个input标签的话,回车会触发表单的提 ...
- pandaboy玩pandas
基于python的三方库pandas的excel表二次开发 import numpy as np import pandas as pd import time from pandas import ...
- NOIp2018模拟赛三十五
两道大数据结构把我砸懵 成绩:未提交 Orz xfz两道正解 A:[BZOJ4049][CREC2014B]mountainous landscape B:CJB的大作(CF改编题)
- python学习笔记:第四天
day04: 一.计算求值 num += 1 等价于 num = num + 1num -= 1 等价于 num = num - 1num *= 2 等价于 num = num * 2num /= 2 ...
- IDEA设置控制台日志 不换行
最新版的IDEA设置控制台不自动换行位置如下:Setting->Editor->General->Console,不要勾选下图项即可.
- Qt之QCryptographicHash
简述 QCryptographicHash类提供了生成密码散列的方法.该类可以用于生成二进制或文本数据的加密散列值.目前支持MD4.MD5.SHA-1.SHA-224.SHA-256.SHA-384和 ...
- ubuntu 各种窗体操作
通用 ctrl+alt+0~9 改变窗体大小和是否显示 alt+F4 关闭窗体菜单键+相应启动器位置的编号打开程序 ctrl+pageup/pagedown 在tab间移动 ctrle+shift+p ...
- 启用Database Vault
步骤1:停止EM.监听.数据库 步骤2:启用Database Vault [oracle@single1 ~]$ cd $ORACLE_HOME/rdbms/lib [oracle@single1 l ...
- 手动配置三大框架整合:Spring+Struts2+mybatis
如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...