dgl.DGLHeteroGraph.has_nodes

DGLHeteroGraph.has_nodes(vids, ntype=None)[source]

Whether the graph has nodes with ids and a particular type.

Parameters:
  • vid (list or tensor) – The array of node IDs.
  • ntype (str, optional) – The node type. Can be omitted if there is only one node type in the graph.
Returns:

a – Binary tensor indicating the existence of nodes with the specified ids and type. a[i]=1 if the graph contains node vids[i] of type ntype, 0 otherwise.

Return type:

tensor

Examples

The following example uses PyTorch backend.

>>> g.has_nodes([0, 1, 2, 3, 4], 'user')
tensor([1, 1, 1, 0, 0])

See also

has_node()