Simple Adjacency matric creation with Pytorch Tensors
I was trying to write a simple function to create a random adjacency matrix in the following way :
def create_adj(a):
    a[a&gt;0.5] = 1
    a[a&lt;=0.5] = 0
    return a

given that a is assumed to be a torch.Tensor() as input, but I get the following error:
TypeError: 'int' object does not support item assignment

If I do things separately (i.e. not inside a function), I simply do:
&gt;&gt; a = torch.rand(3,3)
&gt;&gt; a[a&gt;0.5] = 1
&gt;&gt; a[a&lt;=0.5] = 0

&gt;&gt; a
 tensor([[1., 1., 1.],
         [0., 0., 0.],
         [1., 0., 0.]])

But I don't understand what I'm doing wrong in the function.

I would assume you are not passing the correct variable your create_adj function. As long as a is a torch.tensor, then it should work.
Alternatively, you can directly use the mask as result:
def create_adj(x): 
  return (a &gt; .5).float()

