np.where()
2024-09-04 10:01:27
numpy.where (condition[, x, y])
numpy.where()两种用法
1. np.where(condition, x, y)
满足条件(condition),输出x,不满足输出y。
import numpy as np a = np.arange(10)
b = np.where(a>5, 1, -1)
c = np.where(a, 1, -1) # 0为False,所以第一个输出-1
print(b)
print(c)
[-1 -1 -1 -1 -1 -1 1 1 1 1]
[-1 1 1 1 1 1 1 1 1 1]
2. np.where(condition)
只有条件 (condition),没有x和y,则输出满足条件 (即非0) 元素的坐标.
a = np.arange(0, 100, 10)
b = np.where(a < 50)
c = np.where(a >= 50)[0]
print(b)
print(c)
(array([0, 1, 2, 3, 4], dtype=int64),)
[5 6 7 8 9]
最新文章
- Spark学习(四) -- Spark作业提交
- jQuery基础--样式篇(5)
- [改善Java代码]equals应该考虑null值的情景
- BinaryReader 和BinaryWriter 读写类对象
- Eight(bfs+全排列的哈希函数)
- 基于visual Studio2013解决C语言竞赛题之1082迷宫
- iis7 下配置MVC问题
- usb转串口驱动时会出现“文件的哈希值不在指定的目录”这样的提示
- jquery图片放大镜和遮罩层效果
- 第九章 BootstrapTable的使用
- echart
- Visual Studio高效实用的扩展工具、插件
- c++11 强类型枚举 enum class
- swagger:API在线文档自动生成框架
- 百度api接口_知识积累
- 动态规划DP的优化
- Linux的sysctl 命令参数详解
- 如何在线预览github上的html页面?
- 深入理解Python生成器(Generator)
- Go语言【第六篇】:Go循环语句
热门文章
- Manjaro18+kde 更换壁纸重启失效
- 基于Linux解决登录ssh客户端失败问题—sshd error: could not load host key
- BLE各版本新功能总结
- IPC之ipc_sysctl.c源码解读
- IPC之util.c源码解读
- kubernetes管理机密信息
- maven-将本地jar包添加到本地仓库
- 解决Zabbix某台主机突然频繁告警";Zabbix agent on xxxxxx is unreachable for x minutes";
- Scrapy爬取小说简单逻辑
- eclipse中 Launch configuration的历史记录