How to access pytorch model parameters by index
If I have network with let's say 10 layers including biases, how can I access its i'th layer parameters just by index?

Currently, what I am doing is something like this

for parameter in myModel.parameters():
    parameter.data /= 5 


How could I access parameter.data with an index? For example I'd like to access 9th layer without iterating, such as myModel.parameter.data[8] or something similar.

simply do a :

layers=[x.data for x in myModel.parameters()]


Now it will be a list of weights and biases, in order to access weights of the first layer you can do:

print(layers[0])


in order to access biases of the first layer:

print(layers[1])


and so on.

Remember if bias is false for any particular layer it will have no entries at all, so for example if bias is false for second layer, then layers[3] will actually give weights of the third layer.
