|
1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import numpy as np
- import torch
-
-
- def tril_indices(rows, cols, offset=0):
- return torch.ones(rows, cols, dtype=torch.uint8).tril(offset).nonzero()
-
-
- # x = torch.tensor([1., 2., 3., 4., 5., 6.])
- # m = torch.zeros((3, 3))
- # rows=3
- # cols=3
- # offset=0
- # tril_indices = torch.ones(rows, cols, dtype=torch.uint8).tril(offset).nonzero()
- # m[tril_indices[0], tril_indices[1]] = x
- # print(m)
- def sym(A):
- for i in range(A.shape[0]):
- for j in range(A.shape[1]):
- A[j, i] = A[i, j]
- return A
-
-
- # dm = np.random.rand(6)
- # tri = np.zeros((3, 3))
- # print(tri)
- # print(np.triu_indices(3))
- # print(dm)
- # tri[np.triu_indices(3)] = dm
- # print(tri)
- # A = sym(tri)
- # print(A)
- a = np.zeros((3,3))
- a[0,1] = 5
- a[2,2] = 6
-
- print(a)
- print(np.where(~a.any(axis=1))[0])
- missing_node_index = np.where(~a.any(axis=1))[0][0]
- print(a.shape)
- print(a[missing_node_index, :])
|