当前位置:网站首页>np.where 和 torch.where 用法
np.where 和 torch.where 用法
2022-07-02 01:38:00 【Da_Shan_】
np.where
numpy.where() 有两种用法:
- numpy.where(condition, x, y)
满足condition, 输出x,不满足输出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)
只有condiiton,输出满足condition的元素的下标, 这里的坐标以tuple的形式给出,通常原数组有多少维,输出的tuple中就包含几个数组,分别对应符合条件元素的各维坐标
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()函数的作用是按照一定的规则合并两个tensor类型
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]])
边栏推荐
- 【LeetCode 43】236. The nearest common ancestor of binary tree
- 5g/4g pole gateway_ Smart pole gateway
- VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
- [IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
- Basic concepts of machine learning
- Android high frequency network interview topic must know and be able to compare Android development environment
- 10 minutes to get started quickly composition API (setup syntax sugar writing method)
- 三分钟学会基础k线图知识
- [Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
- [Floyd] post disaster reconstruction
猜你喜欢

Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
![[IVX junior engineer training course 10 papers to get certificates] 09 chat room production](/img/a8/25215e74162b7ab3f29df65681932b.jpg)
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production

6-2漏洞利用-ftp不可避免的问题

Learn about servlets

Edge extraction edges based on Halcon learning_ image. Hdev routine

This is the form of the K-line diagram (pithy formula)

Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months

机器学习基本概念

Three core problems of concurrent programming

PR second training
随机推荐
No converter found for return value of type: class
Just using the way and method of consuming the Internet to land and practice the industrial Internet will not bring long-term development
2022年6月国产数据库大事记
卷積神經網絡(包含代碼與相應圖解)
Study note 2 -- definition and value of high-precision map
Memorabilia of domestic database in June 2022
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface
[Chongqing Guangdong education] Tianshui Normal University universe exploration reference
[IVX junior engineer training course 10 papers] 06 database and services
Edge extraction edges based on Halcon learning_ image. Hdev routine
Docker installing Oracle_ 11g
Introduction to ffmpeg Lib
The role of artificial intelligence in network security
学习笔记24--多传感器后融合技术
II Basic structure of radio energy transmission system
Unity AssetBundle subcontracting
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
学习笔记2--高精度地图定义及价值
GL Studio 5 installation and experience
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd