1
$\begingroup$

I'm inserting a number into the first column of a table, but when I call the table again, the number is not there anymore. Can someone explain to me what I'm doing wrong here?

In[22]:= mass[n]

Out[22]= {5.07637*10^24, 8.24164*10^24, 2.4486*10^24, 3.70276*10^24, 
4.0611*10^24, 8.00275*10^24, 2.74721*10^24}

In[23]:= Insert[mass[n], 1.59084*10^29, 1]

Out[23]= {1.59084*10^29, 5.07637*10^24, 8.24164*10^24, 2.4486*10^24, 
3.70276*10^24, 4.0611*10^24, 8.00275*10^24, 2.74721*10^24}

In[24]:= mass[n][[1]]

Out[24]= 5.07637*10^24

In[25]:= mass[n]

Out[25]= {5.07637*10^24, 8.24164*10^24, 2.4486*10^24, 3.70276*10^24, 
4.0611*10^24, 8.00275*10^24, 2.74721*10^24}
$\endgroup$

closed as off-topic by m_goldberg, Coolwater, José Antonio Díaz Navas, Young, MarcoB Apr 11 '18 at 3:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, Coolwater, José Antonio Díaz Navas, Young, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Insert is not an in-place modification (these end usually with a To like AddTo). In your case, you may use mass[n] = Insert[mass[n], 1.59084*10^29, 1] or PrependTo[mass[n],1.59084*10^29] which are both not really optimal since they involve a copy of the whole list. So use that rarely for longer lists. If you can, try to build vectors, matrices, and more general arrays in one go (e.g. with Table) or at least boil it down to few Join or ArrayFlatten operations. $\endgroup$ – Henrik Schumacher Apr 6 '18 at 13:28

Browse other questions tagged or ask your own question.