0

This is an odd question to phrase, but here's my code:

weights[0] = weights[0] - (1 / outputY.size) * alpha * (errorDiff) * normalizedX[i][0]
weights[1] = weights[1] - (1 / outputY.size) * alpha * (errorDiff) * normalizedX[i][1]
weights[2] = weights[2] - (1 / outputY.size) * alpha * (errorDiff) * normalizedX[i][2]

Where weights and normalizedX are numpy arrays. Is there someway to do that in one line rather than repeat it? Alternatively, I could use a loop, but I'm wondering if there's a more elegant way first.

2
  • You can do a list comprehension of sorts by putting the foot loop between brackets, but it probably wouldn’t look that elegant. Commented Feb 10, 2019 at 16:27
  • wring you function and using np.vectorize Commented Feb 10, 2019 at 16:28

1 Answer 1

5

Assuming weights has dimensions (3,) and normalised is (n, 3):

weights = weights - (1 / outputY.size) * alpha * (errorDiff) * normalizedX[i]

You can also do this in place:

weights -= (1 / outputY.size) * alpha * (errorDiff) * normalizedX[i]
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.