当前位置:网站首页>np. Where and torch Where usage
np. Where and torch Where usage
2022-07-02 01:41:00 【Da_ Shan_】
np.where
numpy.where() There are two uses :
- numpy.where(condition, x, y)
Satisfy condition, Output x, Not satisfied with output 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)
Only condiiton, Output meets condition The subscript of the element , The coordinates here are expressed in tuple Given in the form of , How many dimensions does the original array usually have , Output tuple It contains several arrays , Corresponding to the coordinates of each dimension of the qualified element
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() The function is used to merge two according to certain rules tensor type
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]])
边栏推荐
- [IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
- Unity AssetBundle subcontracting
- 牛客网——华为题库(51~60)
- Architecture evolution from MVC to DDD
- This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
- Basic concepts of machine learning
- Just using the way and method of consuming the Internet to land and practice the industrial Internet will not bring long-term development
- 卷积神经网络(包含代码与相应图解)
- Leetcode 45 Jumping game II (2022.02.14)
- No converter found for return value of type: class
猜你喜欢
LeetCode、3无重复最长子序列
Implementation of Weibo system based on SSM
Memorabilia of domestic database in June 2022
Exclusive delivery of secret script move disassembly (the first time)
Feature extraction and detection 16 brisk feature detection and matching
Leetcode, 3 repeatless longest subsequence
Self drawing of menu items and CListBox items
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
The smart Park "ZhongGuanCun No.1" subverts your understanding of the park
Three core problems of concurrent programming
随机推荐
【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码
matlab 实现语音信号重采样和归一化,并播放比对效果
Tencent cloud techo youth dream campus trip into Wuhan University
Feature extraction and detection 16 brisk feature detection and matching
I Brief introduction of radio energy transmission technology
NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
Laravel artisan 常用命令
What is AQS and its principle
Brief introduction to the development of mobile network
Brief description of grafana of # yyds dry goods inventory # Prometheus
2022年6月国产数据库大事记
学习笔记24--多传感器后融合技术
VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
[Maya] the error of importing Maya into Metahuman
uTools
The role of artificial intelligence in network security
卷積神經網絡(包含代碼與相應圖解)
Ks006 student achievement management system based on SSM
What are the skills of spot gold analysis?
MySQL application day02