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]

最新文章

  1. Spark学习(四) -- Spark作业提交
  2. jQuery基础--样式篇(5)
  3. [改善Java代码]equals应该考虑null值的情景
  4. BinaryReader 和BinaryWriter 读写类对象
  5. Eight(bfs+全排列的哈希函数)
  6. 基于visual Studio2013解决C语言竞赛题之1082迷宫
  7. iis7 下配置MVC问题
  8. usb转串口驱动时会出现“文件的哈希值不在指定的目录”这样的提示
  9. jquery图片放大镜和遮罩层效果
  10. 第九章 BootstrapTable的使用
  11. echart
  12. Visual Studio高效实用的扩展工具、插件
  13. c++11 强类型枚举 enum class
  14. swagger:API在线文档自动生成框架
  15. 百度api接口_知识积累
  16. 动态规划DP的优化
  17. Linux的sysctl 命令参数详解
  18. 如何在线预览github上的html页面?
  19. 深入理解Python生成器(Generator)
  20. Go语言【第六篇】:Go循环语句

热门文章

  1. Manjaro18+kde 更换壁纸重启失效
  2. 基于Linux解决登录ssh客户端失败问题—sshd error: could not load host key
  3. BLE各版本新功能总结
  4. IPC之ipc_sysctl.c源码解读
  5. IPC之util.c源码解读
  6. kubernetes管理机密信息
  7. maven-将本地jar包添加到本地仓库
  8. 解决Zabbix某台主机突然频繁告警&quot;Zabbix agent on xxxxxx is unreachable for x minutes&quot;
  9. Scrapy爬取小说简单逻辑
  10. eclipse中 Launch configuration的历史记录