[SOLVED] Add element to numpy array without changing the name

Issue

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

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])

Answered By – TYSH

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *