# Multiply an array by an especific number at an specific position in the array

If I have a table of let's say 2000 values in column 1 and 2, how can I multiply only an specific part of that table by a certain number?. In particular, I want to multiply the second column only from row 3 to row 2000 (not including row 1 and 2) by a number (let's say 5) and leaving column 1 intact. I would very much appreciate your help.

I am aware of Elegant operations on matrix rows and columns but I could not find a solution for this in particular there.

• table[[3;;2000,2]]=5 table[[3;;2000,2]]? – kglr Apr 18 '20 at 0:57
• try also MapAt[5 #&, table, {3;;2000,2}] – kglr Apr 18 '20 at 0:59
• Thank you kglr. The first method works but I cannot access column 1. I would like to have column 2 multiplied by the number while at the same time column 1 does not dissapear. The second method does not work: If I have table = Table[{1, 2}, 10]; and then I use MapAt[5 # &, table, {3 ;; 10, 2}], then I get {{1, 2}, {1, 2}, {78125, 3906250}, {78125, 3906250}, {78125, 3906250}, {78125, 3906250}, {78125, 3906250}, {78125, 3906250}, {78125, 3906250}, {78125, 3906250}} – John Apr 18 '20 at 1:16

table = Table[{1, 2}, 10];

To create new tables without changing table:

table2 = Module[{t = #}, t[[2 ;; 10, 2]] = 5 t[[2 ;; 10, 2]]; t] & @ table;
table3 = Module[{t = #}, t = MapAt[5 # &, t, {2 ;; 10, 2}]] & @ table;
table4 = Module[{t = #}, t[[2 ;; 10, 2]] *= 5; t] & @ table;

Multiplying the row range $$a_1$$ to $$a_2$$ and column range $$b_1$$ to $$b_2$$ by the scalar $$c$$ in the matrix $$A$$:
• That's what any line of code that depends on the previous state of $A$ will do. If you want a line of code that fixes $A$ no matter what, you will have to hardcode the value into the line A[[a1;;a2, b1;;b2]] = c * hard_coded_A[[a1;;a2, b1;;b2]]. This is bad practice. If you write your notebook sequentially assuming that line will be hit only once, it will work. It will be more readable that way too. – dskeletov Apr 18 '20 at 1:22