# How to set multiple parameters to zero?

Say I have the matrix

A = {{a,b,c,d,e}, {f,g,h,j,k}}


and I want to set some of these to zero. I have been doing this via

A/.{a->0, b->0}.


Is there a way to set a bunch to zero at once? I am dealing with many more parameters than 8 and would like to not type "->0," a million times. I tried

A/.{a,b,c}->0


But this just sets the list {a,b,c} to 0 (I believe). Thanks for the help.

• Look up ReplacePart[]. But, you do not have a matrix, since your "rows" do not have the same dimensions. – J. M.'s ennui Jun 7 '16 at 15:49
• Whoops, thanks! – user46348 Jun 7 '16 at 16:07

In terms of generating the replacement rule efficiently, you can do the following:

A = {{a, b, c, d, e}, {f, g, h, j}};
A /. Thread[{a, b, c} -> 0]

(*{{0, 0, 0, d, e}, {f, g, h, j}}*)

• Thanks a bunch! Will put to use immediately! – user46348 Jun 7 '16 at 16:35
• Great to hear, enjoy! – Yves Klett Jun 7 '16 at 17:30

Or you can use Map

A = {{a, b, c, d, e}, {f, g, h, j}};
A /. (# -> 0 & /@ {a, b, c})


Update: or to have fun.

Fold[#1 /. #2 -> 0 &, A, {a, b, c}]


I would argue that the most idiomatic solution is

A /. a | b | c -> 0

• Since he has a long list of parameters that will become zero.. A /. Alternatives @@ {a, b,c} -> 0 – BlacKow Jun 7 '16 at 20:46