r"""Remove the specified nodes and return a new graph. Also delete the features. Edges that connect from/to the nodes will be removed as well. After the removal, DGL re-labels the remaining nodes and edges with IDs from 0. Parameters ---------- nids : int, Tensor, iterable[
(g, nids, ntype=None, store_ids=False)
| 1824 | |
| 1825 | |
| 1826 | def remove_nodes(g, nids, ntype=None, store_ids=False): |
| 1827 | r"""Remove the specified nodes and return a new graph. |
| 1828 | |
| 1829 | Also delete the features. Edges that connect from/to the nodes will be |
| 1830 | removed as well. After the removal, DGL re-labels the remaining nodes and edges |
| 1831 | with IDs from 0. |
| 1832 | |
| 1833 | Parameters |
| 1834 | ---------- |
| 1835 | nids : int, Tensor, iterable[int] |
| 1836 | The nodes to be removed. |
| 1837 | ntype : str, optional |
| 1838 | The type of the nodes to remove. Can be omitted if there is |
| 1839 | only one node type in the graph. |
| 1840 | store_ids : bool, optional |
| 1841 | If True, it will store the raw IDs of the extracted nodes and edges in the ``ndata`` |
| 1842 | and ``edata`` of the resulting graph under name ``dgl.NID`` and ``dgl.EID``, |
| 1843 | respectively. |
| 1844 | |
| 1845 | Return |
| 1846 | ------ |
| 1847 | DGLGraph |
| 1848 | The graph with nodes deleted. |
| 1849 | |
| 1850 | Notes |
| 1851 | ----- |
| 1852 | |
| 1853 | This function discards the batch information. Please use |
| 1854 | :func:`dgl.DGLGraph.set_batch_num_nodes` |
| 1855 | and :func:`dgl.DGLGraph.set_batch_num_edges` on the transformed graph |
| 1856 | to maintain the information. |
| 1857 | |
| 1858 | Examples |
| 1859 | -------- |
| 1860 | |
| 1861 | >>> import dgl |
| 1862 | >>> import torch |
| 1863 | |
| 1864 | **Homogeneous Graphs** |
| 1865 | |
| 1866 | >>> g = dgl.graph((torch.tensor([0, 0, 2]), torch.tensor([0, 1, 2]))) |
| 1867 | >>> g.ndata['hv'] = torch.arange(3).float().reshape(-1, 1) |
| 1868 | >>> g.edata['he'] = torch.arange(3).float().reshape(-1, 1) |
| 1869 | >>> g = dgl.remove_nodes(g, torch.tensor([0, 1])) |
| 1870 | >>> g |
| 1871 | Graph(num_nodes=1, num_edges=1, |
| 1872 | ndata_schemes={'hv': Scheme(shape=(1,), dtype=torch.float32)} |
| 1873 | edata_schemes={'he': Scheme(shape=(1,), dtype=torch.float32)}) |
| 1874 | >>> g.ndata['hv'] |
| 1875 | tensor([[2.]]) |
| 1876 | >>> g.edata['he'] |
| 1877 | tensor([[2.]]) |
| 1878 | |
| 1879 | **Heterogeneous Graphs** |
| 1880 | |
| 1881 | >>> g = dgl.heterograph({ |
| 1882 | ... ('user', 'plays', 'game'): (torch.tensor([0, 1, 1, 2]), |
| 1883 | ... torch.tensor([0, 0, 1, 1])), |
no test coverage detected