当前位置:网站首页>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 to get certificates] 09 chat room production
- Using tabbar in wechat applet
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- Basic concepts of machine learning
- Learn C language from scratch day 025 (maze)
- Android high frequency network interview topic must know and be able to compare Android development environment
- Matlab uses resample to complete resampling
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
- [IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
- Should enterprises choose server free computing?
猜你喜欢

What are the skills of spot gold analysis?

Basic concepts of machine learning

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

This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable

Edge computing accelerates live video scenes: clearer, smoother, and more real-time

MySQL application day02

Learn about servlets

5g/4g pole gateway_ Smart pole gateway

6-3漏洞利用-SSH环境搭建

微信小程序中使用tabBar
随机推荐
ES6 new method of string
uTools
Modeling essays series 124 a simple coding method
Experimental reproduction of variable image compression with a scale hyperprior
1217 supermarket coin processor
TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
Learning note 3 -- Key Technologies of high-precision map (Part 1)
5g/4g pole gateway_ Smart pole gateway
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
Game thinking 15: thinking about the whole region and sub region Services
学习笔记25--多传感器前融合技术
Failed to transform file 'xxx' to match attributes
卷積神經網絡(包含代碼與相應圖解)
遊戲思考15:全區全服和分區分服的思考
学习笔记3--高精度地图关键技术(上)
new和malloc的区别
Convolutional neural network (including code and corresponding diagram)
Raspberry pie 4B learning notes - IO communication (1-wire)
Quatre stratégies de base pour migrer la charge de travail de l'informatique en nuage
只是以消费互联网的方式和方法来落地和实践产业互联网,并不能够带来长久的发展