I use loss.backward() and optimizer.step() to train my NeuralNetwork, but I want to change the data of weights before testing. My target is that, when weight is less than one interval or zero, the weight is set to a fixed value. my code is as following:
for f in neuralnetwork.layer.weight.data:
if neuralnetwork.layer.weight.data <= 0:
neuralnetwork.layer.weight.data = 0
but this code is not correct, how can I change my code?
thanks for tell me how to do! thanks very much

image.png805×133 4.07 KB