dgl.sparse.power
- dgl.sparse.power(A: SparseMatrix, scalar: Number | Tensor) SparseMatrix [source]
逐元素指数运算
SparseMatrix
,等同于A ** scalar
。- Parameters:
A (SparseMatrix) – Sparse matrix
标量 (标量) – 指数
- Returns:
稀疏矩阵
- Return type:
示例
>>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]]) >>> val = torch.tensor([10, 20, 30]) >>> A = dglsp.spmatrix(indices, val) >>> dglsp.power(A, 2) SparseMatrix(indices=tensor([[1, 0, 2], [0, 3, 2]]), values=tensor([100, 400, 900]), shape=(3, 4), nnz=3)
>>> D = dglsp.diag(torch.arange(1, 4)) >>> dglsp.power(D, 2) SparseMatrix(indices=tensor([[0, 1, 2], [0, 1, 2]]), values=tensor([1, 4, 9]), shape=(3, 3), nnz=3)