I have an array of two elements
q = [0, 0]
The values of the elements change during code execution in the following form:
q[0] = hereHumber q[1] = 1
Is it possible to change elements in one line? Maybe with Numpy? how? :))))
CodePudding user response:
Yes you can. You can pass one value that will be added to all, or a same'size list and it'll be added element-wise
import numpy as np
a = np.array([0, 0])
print(a) # [0 0]
a = 2
print(a) # [2 2]
a = [2, 4]
print(a) # [4 6]
CodePudding user response:
It is possible with default python list comprehension.
q = [0, 0]
q = [q[enum[0]] num for enum, num in zip(enumerate(q), [here_number, 1])]
But numpy-way is better.