当前位置:网站首页>np.where 和 torch.where 用法
np.where 和 torch.where 用法
2022-07-02 01:38:00 【Da_Shan_】
np.where
numpy.where() 有两种用法:
- numpy.where(condition, x, y)
满足condition, 输出x,不满足输出y
condition = [[True, False], [True, True]]
x = [[1, 2], [3, 4]]
y = [[9, 8], [7, 6]]
np.where(condition, x, y)
>>>
[[1 8]
[3 4]]
- numy.where(condition)
只有condiiton,输出满足condition的元素的下标, 这里的坐标以tuple的形式给出,通常原数组有多少维,输出的tuple中就包含几个数组,分别对应符合条件元素的各维坐标
x = np.arange(12).reshape((2, 3, 2))
z = np.where(x > 7)
>>>
[[[ 0 1]
[ 2 3]
[ 4 5]]
[[ 6 7]
[ 8 9]
[10 11]]]
(array([1, 1, 1, 1]), array([1, 1, 2, 2]), array([0, 1, 0, 1]))
torch.where
torch.where()函数的作用是按照一定的规则合并两个tensor类型
import torch
a = torch.randn(2, 3)
b = torch.ones_like(a)
com = torch.where(a > 0, a, b)
>>>
tensor([[-0.9728, 1.2321, -0.1471],
[ 0.3736, 0.5832, 0.5332]])
tensor([[1.0000, 1.2321, 1.0000],
[0.3736, 0.5832, 0.5332]])
边栏推荐
- Should enterprises choose server free computing?
- Data visualization in medical and healthcare applications
- 游戏思考15:全区全服和分区分服的思考
- 迁移云计算工作负载的四个基本策略
- D discard the virtual recovery method
- The technology boss is ready, and the topic of position C is up to you
- matlab 使用 audioread 、 sound 读取和播放 wav 文件
- Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
- Fastadmin controls the length of fields in the table
- 并发编程的三大核心问题
猜你喜欢

Learning note 24 - multi sensor post fusion technology

6-2漏洞利用-ftp不可避免的问题

Study note 2 -- definition and value of high-precision map

The technology boss is ready, and the topic of position C is up to you

What is AQS and its principle

Raspberry pie 4B learning notes - IO communication (1-wire)

LeetCode、3无重复最长子序列

【疾病检测】基于BP神经网络实现肺癌检测系统含GUI界面

Design and control of multi rotor aircraft (VII) -- sensor calibration and measurement model
![[Maya] the error of importing Maya into Metahuman](/img/46/46bd1c2d507c9e48ef8c066c54231d.jpg)
[Maya] the error of importing Maya into Metahuman
随机推荐
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production
MPLS experiment operation
Electronic Society C language level 1 32, calculate the power of 2
Exclusive delivery of secret script move disassembly (the first time)
[Floyd] post disaster reconstruction
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
基于SSM实现微博系统
How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
卷積神經網絡(包含代碼與相應圖解)
Four basic strategies for migrating cloud computing workloads
What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation
技术大佬准备就绪,话题C位由你决定
How to compress video size while adding watermark with one click?
游戏思考15:全区全服和分区分服的思考
Android: the kotlin language uses grendao3, a cross platform app development framework
The author is more willing to regard industrial Internet as a concept much richer than consumer Internet
Modeling essays series 124 a simple coding method
卷积神经网络(包含代码与相应图解)
No converter found for return value of type: class
k线图形态这样记(口诀篇)