How can I generate lots of FC layer in a simple way?
I would like to make 640 fc layer.
(in def init)
self.fc0 = nn.Linear(120, M)
self.fc1 = nn.Linear(120, M)
.....
self.fc638 = nn.Linear(120, M)
self.fc639 = nn.Linear(120, M)

(in def forward)
x[:,:,0,:] = self.fc0(x[:,:,0,:])
x[:,:,1,:] = self.fc0(x[:,:,1,:])
.......
x[:,:,639,:] = self.fc639(x[:,:,639,:])

How can I execute the code above in simpler way ?

Use containers:
class MultipleFC(nn.Module):
  def __init__(self, num_layers, M):
    self.layers = nn.ModuleList([nn.Linear(120, M) for _ in range(num_layers)])

  def forward(self, x):
    y = torch.empty_like(x)  # up to third dim should be M
    for i, fc in enumerate(self.layers):
      y[..., i, :] = fc(x[..., i, :])
    return y

