I'm very new to coding and have searched heavily to try to find an answer to this.
I have a (10,10) array and am trying to add across two specific rows a specific value. I am also trying to do it with a single line of code.
Specifically, I am trying to add across the sixth and 8th row of the array the value present at the specific element of that same array (5,5). My array is defined as 'a'.
I feel like a for loop could work, but the problem is that 1) this is two lines of code, and 2, it produces something close but is adding that element to those two rows, twice instead of once.
for x in a[(5,7),:]:
a[(5,7),:] = (x (a[5,5])):
CodePudding user response:
You've probably over-complicated this a bit. If I understand correctly, you should do something like this:
a[(5, 7), :] = a[5, 5]
The =
operator is an "in-place" addition. This is the same as doing this:
a[(5, 7), :] = a[(5, 7), :] a[5, 5]