arr
is a n-dimensional numpy array.
How to change sign of every element of arr with an odd sum of indices?
For example, arr[0, 1, 2]
needs a sign change because it has a sum of indices 0 + 1 + 2 = 3
, which is odd.
When I convert arr
to a list, I notice that every second element in the list are elements that needs a sign change.
Another example:
Original array:
[[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]]
[[ 9 10 11]
[12 13 14]
[15 16 17]]
[[18 19 20]
[21 22 23]
[24 25 26]]]
Array with signs changed:
[[[ 0 -1 2]
[ -3 4 -5]
[ 6 -7 8]]
[[ -9 10 -11]
[12 -13 14]
[-15 16 -17]]
[[18 -19 20]
[-21 22 -23]
[24 -25 26]]]