How do you mutate a 0-dimensional tensor? I tried

```
x = torch.tensor(1)
x[0] = 2
```

but that gives `UserWarning: invalid index of a 0-dim tensor.`

How do you mutate a 0-dimensional tensor? I tried

```
x = torch.tensor(1)
x[0] = 2
```

but that gives `UserWarning: invalid index of a 0-dim tensor.`

It’s 0-dim, so

```
>>> import torch
>>> torch.tensor(1)[()]
tensor(1)
>>> x = torch.tensor(1)
>>> x[()]=2
>>> x
tensor(2)
```

1 Like