# dgl.DGLGraph.apply_nodes¶

DGLGraph.apply_nodes(func='default', v='__ALL__', inplace=False)[source]

Apply the function on the nodes to update their features.

If None is provided for func, nothing will happen.

Parameters: func (callable or None, optional) – Apply function on the nodes. The function should be a Node UDF. v (int, iterable of int, tensor, optional) – The node (ids) on which to apply func. The default value is all the nodes. inplace (bool, optional) – If True, update will be done in place, but autograd will break.

Examples

Note

Here we use pytorch syntax for demo. The general idea applies to other frameworks with minor syntax change (e.g. replace torch.tensor with mxnet.ndarray).

>>> import torch as th
>>> g = dgl.DGLGraph()

>>> # Increment the node feature by 1.