0

I am coding a neural network in python, and need to adjust my weights. In order to do so, I need to add my change variable to an element of my weights array. However, I don't know how to do this. The code would look like:

weights = numpy.array([1, 2, 3])
change = 1
weights[0]+= change
print(weights)
-- [2, 2, 3]

I have tried this, but it does not seem to work. Thanks in advance for any answers.

1
  • 1
    What isn't working? Be descriptive. Commented Jul 8, 2017 at 3:10

1 Answer 1

1

If you're trying to add your variable 'change' to just the first element of the weights array, then your code works fine. if you are trying to add 'change' to all elements of the weights array, simply put

weights=numpy.array([1,2,3])
change=1
weights+=change
print(weights)

this code will add the change to all the elements. I'm assuming that this is what you're trying to do because that would make the most sense in the context of a neural network. if this is not your problem, be more specific on what you are trying to do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.