当前位置:网站首页>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]])
边栏推荐
- Learn C language from scratch day 025 (maze)
- Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation
- Load and domcontentloaded in JS
- 游戏思考15:全区全服和分区分服的思考
- II Basic structure of radio energy transmission system
- 技术大佬准备就绪,话题C位由你决定
- 学习笔记24--多传感器后融合技术
- Design and implementation of radio energy transmission system
- 机器学习基本概念
- 开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
猜你喜欢
Convolutional neural network (including code and corresponding diagram)
What is AQS and its principle
6-2 vulnerability exploitation - inevitable problems of FTP
Four basic strategies for migrating cloud computing workloads
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
[Floyd] post disaster reconstruction
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
Docker installing Oracle_ 11g
现货黄金分析的技巧有什么呢?
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
随机推荐
Edge extraction edges based on Halcon learning_ image. Hdev routine
Introduction to ffmpeg Lib
[image enhancement] vascular image enhancement based on frangi filter with matlab code
Laravel artisan 常用命令
[Maya] the error of importing Maya into Metahuman
Brief introduction to the development of mobile network
How can I batch produce the same title for the video?
Game thinking 15: thinking about the whole region and sub region Services
学习笔记3--高精度地图关键技术(上)
学习笔记2--高精度地图定义及价值
Matlab uses audioread and sound to read and play WAV files
matlab 使用 audioread 、 sound 读取和播放 wav 文件
卷積神經網絡(包含代碼與相應圖解)
Parted command
LeetCode、3无重复最长子序列
[rust web rokcet Series 1] Hello, world and get, post, put, delete
Design and control of multi rotor aircraft (VII) -- sensor calibration and measurement model
卷积神经网络(包含代码与相应图解)
Failed to transform file 'xxx' to match attributes
Feature extraction and detection 16 brisk feature detection and matching