'Add element to numpy array without changing the name

I want to add a single element : -globals()["q"+str(i)][0][u] to the array mainarray while being inside a loop.

for i in mylist:
    for u in 0,5,10:
      np.append(mainarray['C'][u][i],-globals()["q"+str(i)][0][u])

After finishing the loop the changes are not save, how can I achieve that?



Solution 1:[1]

I had to create a new array with a "+1" dimension of length.

newarray=pd.Series([])
newarray[at_type][at1] = np.zeros((old_length+1))

Then I started the loop.

for i in mylist:
    for u in 0,5,10:
      newarray['C'][u][i]=np.append(mainarray['C'][u][i],-globals()["q"+str(i)][0][u])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TYSH