当前位置:网站首页>numpy.where
numpy.where
2022-08-01 23:21:00 【Wanderer001】
numpy.where(condition[, x, y])
Return elements chosen from x or y depending on condition.
Note:
When only condition is provided, this function is a shorthand for np.asarray(condition).nonzero(). Using nonzero directly should be preferred, as it behaves correctly for subclasses. The rest of this documentation covers only the case where all three arguments are provided.
Parameters:condition:array_like, bool
Where True, yield x, otherwise yield y.
x, y:array_like
Values from which to choose. x, y and condition need to be broadcastable to some shape.
Returns:
out:ndarray
An array with elements from x where condition is True, and elements from y elsewhere.
See also
The function that is called when x and y are omitted
Notes
If all the arrays are 1-D, where is equivalent to:
[xv if c else yv
for c, xv, yv in zip(condition, x, y)]
Examples
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.where(a < 5, a, 10*a)
array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90])This can be used on multidimensional arrays too:
>>> np.where([[True, False], [True, True]],
... [[1, 2], [3, 4]],
... [[9, 8], [7, 6]])
array([[1, 8],
[3, 4]])The shapes of x, y, and the condition are broadcast together:
>>> x, y = np.ogrid[:3, :4]
>>> np.where(x < y, x, 10 + y) # both x and 10+y are broadcast
array([[10, 0, 0, 0],
[10, 11, 1, 1],
[10, 11, 12, 2]])>>> a = np.array([[0, 1, 2],
... [0, 2, 4],
... [0, 3, 6]])
>>> np.where(a < 4, a, -1) # -1 is broadcast
array([[ 0, 1, 2],
[ 0, 2, -1],
[ 0, 3, -1]])边栏推荐
- 6134. 找到离给定两个节点最近的节点-力扣双百代码
- How to better understand and do a good job?
- leetcode刷题
- ELK日志采集
- 云原生DevOps环境搭建
- y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)
- excel edit a cell without double clicking
- Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
- 【参营经历贴】2022网安夏令营
- 深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
猜你喜欢

Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D 题解

云原生DevOps环境搭建

Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training

深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练

Access the selected node in the console

解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”

【参营经历贴】2022网安夏令营

Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution

chrome复制一张图片的base64数据

系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
随机推荐
怎样做才能让这条SQL变成一条危险的SQL?
JAX-based activation function, softmax function and cross entropy function
The monthly salary of the test post is 5-9k, how to increase the salary to 25k?
excel remove all carriage return from a cell
How to better understand and do a good job?
excel edit a cell without double clicking
【C语言进阶】文件操作(二)
6133. 分组的最大数量
qt-faststart installation and use
[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环
ELK日志采集
CF1703G Good Key, Bad Key
prim生成树
y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)
毫秒级!千万人脸库快速比对,上亿商品图片检索,背后的极速检索用了什么神器?
数据库表设计规则
云原生DevOps环境搭建
IDEA入门看这一篇就够了
[C language advanced] file operation (2)
npm npm