当前位置:网站首页>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]])
边栏推荐
- Basic number theory -- Gauss elimination
- Introduction to ffmpeg Lib
- 迁移云计算工作负载的四个基本策略
- Convolutional neural network (including code and corresponding diagram)
- Day 13 of hcip (relevant contents of BGP agreement)
- [IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
- Raspberry pie 4B learning notes - IO communication (1-wire)
- Load and domcontentloaded in JS
- Appium inspector can directly locate the WebView page. Does anyone know the principle
- matlab 使用 resample 完成重采样
猜你喜欢

The role of artificial intelligence in network security
![[IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games](/img/69/44219af52baef20cedec3870147589.jpg)
[IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games

Implementation of Weibo system based on SSM

Basic concepts of machine learning

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

How can I batch produce the same title for the video?
![Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation](/img/eb/b1382428d6578b8561d7fcc1a2a5cd.jpg)
Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation
![[Maya] the error of importing Maya into Metahuman](/img/46/46bd1c2d507c9e48ef8c066c54231d.jpg)
[Maya] the error of importing Maya into Metahuman

电商系统中常见的9大坑,你踩过没?

Hcip day 14 (MPLS protocol)
随机推荐
Matlab uses audioread and sound to read and play WAV files
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
Electronic Association C language level 1 33, odd even number judgment
new和malloc的区别
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
Memorabilia of domestic database in June 2022
现货黄金分析的技巧有什么呢?
10 minutes to get started quickly composition API (setup syntax sugar writing method)
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
k线图形态这样记(口诀篇)
What is AQS and its principle
Brief description of grafana of # yyds dry goods inventory # Prometheus
Ubuntu20.04 PostgreSQL 14 installation configuration record
如何远程、在线调试app?
uTools
We should make clear the branch prediction
Basic number theory -- Gauss elimination
Feature extraction and detection 16 brisk feature detection and matching
Learning note 3 -- Key Technologies of high-precision map (Part 1)
6-3漏洞利用-SSH环境搭建