当前位置:网站首页>import torch_ Data view of geometric
import torch_ Data view of geometric
2022-06-12 13:05:00 【Dongxuan】
Welcome to the column torch_geometric

Data Handling of Graphs
A processing library torch_geometric. I also found this class when watching others share code , It is out of place with the usual class .
torch_geometric.data.Data, It can simply represent a graph data . It contains the following properties
data.x: Node characteristics [ Number of nodes , Node feature dimension ][num_nodes, num_node_features]data.edge_index: It has to be this shape[2, num_edges]and typetorch.long. Must be serial number . First of all, yours. data.x It determines the order of each node index . Then specify the edges according to this sequence number , The first row of the edge is the source node , The second node is the target node .data.edge_attr: Feature representation of edges[num_edges, num_edge_features]data.y: A label for graph data , It can be a node classification task[num_nodes, *], It can also be a graph classification task[1, *]data.pos: The coordinates of point , For example, the point is in the three-dimensional coordinate system ,num_dimensions Namely 3[num_nodes, num_dimensions]
We can expand Data List of properties , For example data.face To express 3d In the clouds face The concept of . Use the sequence number of points to specify which three points form a face . [3, num_faces] and type torch.long.
A bunch of runnable examples
Example ①
import torch
from torch_geometric.data import Data
edge_index = torch.tensor([[0, 1, 1, 2],
[1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = Data(x=x, edge_index=edge_index)
>>> Data(edge_index=[2, 4], x=[3, 1])perhaps edge_index The second way to write
Example ②
import torch
from torch_geometric.data import Data
edge_index = torch.tensor([[0, 1],
[1, 0],
[1, 2],
[2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = Data(x=x, edge_index=edge_index.t().contiguous())
>>> Data(edge_index=[2, 4], x=[3, 1])Let's output the built graph data information .
print(data.keys)
>>> ['x', 'edge_index']
print(data['x'])
>>> tensor([[-1.0],
[0.0],
[1.0]])
for key, item in data:
print(f'{key} found in data')
>>> x found in data
>>> edge_index found in data
'edge_attr' in data
>>> False
data.num_nodes
>>> 3
data.num_edges
>>> 4
data.num_node_features
>>> 1
data.has_isolated_nodes()
>>> False
data.has_self_loops()
>>> False
data.is_directed()
>>> False
# Transfer data object to GPU.
device = torch.device('cuda')
data = data.to(device)边栏推荐
- 嵌入式系統硬件構成-基於ARM的嵌入式開發板介紹
- About paiwen
- Image comparison function after registration itk:: checkerboardimagefilter
- 镜像扫描工具预研
- itk itk::BSplineDeformableTransform
- 大一女生废话编程爆火!懂不懂编程的看完都拴Q了
- Will the next star of PPT for workplace speech be you [perfect summary] at the moment
- torch_geometric mini batch 的那些事
- Constant time delete / find any element in array
- VTK three views
猜你喜欢

leetcode 47. Permutations II 全排列 II(中等)

LeetCode滑动窗口刷题总结
![[database] Navicat -- Oracle database creation](/img/40/95d222acd0ae85bd9a4be66aa20d1d.png)
[database] Navicat -- Oracle database creation

"New continent" of mobile application going to sea

Hardware composition of embedded system - introduction of embedded development board based on ARM

The 4th Zhejiang CTF preliminary contest web pppop
![[HXBCTF 2021]easywill](/img/a2/8bf7d78fccf0d365490a84a8a9883d.jpg)
[HXBCTF 2021]easywill

Online picture material

【刷题篇】超级洗衣机

IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V
随机推荐
大一女生废话编程爆火!懂不懂编程的看完都拴Q了
Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
list和dict的应用
Volume mount and mirror creation
智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S
One line of code to implement shell if else logic
号称下一代监控系统!来看看它有多牛逼
Install MySQL database independently on Debian 10
OpenMAX (OMX)框架
路由信息的来源
看完这一篇就够了,web中文开发
verilog-mode的简要介绍
Overview of embedded system 3- development process, learning basis and methods of embedded system
干货满满,这些知识你必须拿下
R语言ggplot2可视化:使用ggrepel包在线图(line plot)的尾端那个数据点添加数值标签(number label)
About paiwen
Build an embedded system software development environment - build a cross compilation environment
Further understanding of the network
C#DBHelper_FactoryDB_GetConn
手把手教你IDEA创建SSM项目结构