当前位置:网站首页>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]])
边栏推荐
- D discard the virtual recovery method
- Look at the industrial Internet from a new perspective and seek the correct ways and methods of industrial Internet
- Parted command
- 大学的知识是否学而无用、过时?
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- [Maya] the error of importing Maya into Metahuman
- Appium inspector can directly locate the WebView page. Does anyone know the principle
- 学习笔记25--多传感器前融合技术
- Day 13 of hcip (relevant contents of BGP agreement)
- Matlab uses resample to complete resampling
猜你喜欢

城市选择器组件实现原理

What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation

Edge extraction edges based on Halcon learning_ image. Hdev routine
![[Maya] the error of importing Maya into Metahuman](/img/46/46bd1c2d507c9e48ef8c066c54231d.jpg)
[Maya] the error of importing Maya into Metahuman

How to compress video size while adding watermark with one click?

New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port

matlab 实现语音信号重采样和归一化,并播放比对效果

SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5

学习笔记24--多传感器后融合技术

How can I batch produce the same title for the video?
随机推荐
电商系统中常见的9大坑,你踩过没?
Electronic Society C language level 1 32, calculate the power of 2
学习笔记2--高精度地图定义及价值
Convolutional neural network (including code and corresponding diagram)
Based on Simulink and FlightGear, the dynamic control of multi rotor UAV in equilibrium is modeled and simulated
10 minutes to get started quickly composition API (setup syntax sugar writing method)
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
Learning note 3 -- Key Technologies of high-precision map (Part 1)
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
Penser au jeu 15: penser au service complet et au sous - service
Learn about servlets
迁移云计算工作负载的四个基本策略
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
uTools
6-2漏洞利用-ftp不可避免的问题
三分钟学会基础k线图知识
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port