当前位置:网站首页>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]])
边栏推荐
- Edge extraction edges based on Halcon learning_ image. Hdev routine
- Parted command
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
- [Floyd] post disaster reconstruction
- NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
- 学习笔记2--高精度地图定义及价值
- 电子协会 C语言 1级 32、计算2的幂
- LeetCode、3无重复最长子序列
- Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
- Brief introduction to the development of mobile network
猜你喜欢

How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
![[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility](/img/8b/e51867cfe9d200ac385e1d1f01e4b3.jpg)
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility

Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories

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

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

Implementation principle of city selector component

The smart Park "ZhongGuanCun No.1" subverts your understanding of the park

Appium inspector can directly locate the WebView page. Does anyone know the principle

6-3 vulnerability exploitation SSH environment construction

ES6 new method of string
随机推荐
Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
Failed to transform file 'xxx' to match attributes
Discussion on the idea of platform construction
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
Load and domcontentloaded in JS
LeetCode、3无重复最长子序列
Learn about servlets
A problem about function template specialization
There are spaces in the for loop variable in the shell -- IFS variable
MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
PR second training
Three core problems of concurrent programming
遊戲思考15:全區全服和分區分服的思考
学习笔记25--多传感器前融合技术
Laravel artisan 常用命令
Electronic Association C language level 1 33, odd even number judgment
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
Modeling essays series 124 a simple coding method
GL Studio 5 installation and experience
Android high frequency network interview topic must know and be able to compare Android development environment