Array of neural net objects

Is it possible to create an array of neural network objects? I’m sorry if this has been posted somewhere, but I can’t seem to find it.

Here’s how I define my nn.Module:

If I want to now define multiple instances of this network, e.g.
I get the error, ’ ‘Net’ object does not support item assignment’

Net is a class. Probably it should be net[0] = Net1(10). Check that it should be first brackets. Net1[10] would automatically cause it to assume that Net1 is a dict or a list or tuple etc.

Additionally to what @Sandipan_Majhi said: in case you would like to wrap these models in a list, which would properly register these models, use e.g. nn.ModuleList instead of a Python list (same for nn.ModuleDict vs. dict).

1 Like