# Replace elements of indexed list by list of rules

I have an array bs that contains many indexed elements b[ ]. I want to define the values of bs by a list of replacement rules. However replacement does not work. It works only if I replace every element individually that is not comfortable if you have many variables.

bs = Array[b, 10]
rule1 = bs -> {2, 4, 1, 1, 5, 2, 6, 2, 5, 2}
(* {b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9],b[10]}->{2,4,1,1,5,2,6,2,5,2} *)

b[1] /. rule1
(* b[1] *)

rule2 = {b[1] -> 2, b[2] -> 4};
b[1] + b[2] /. rule2
(* 6 *)

Summary of solutions for different cases (almost all were given in the answers)

If we have 1 list we can replace by

Thread[bs -> {2, 4, 1, 1, 5, 2, 6, 2, 5, 2}].

If we have to replace 2 lists we can do

If we want to replace a multidimensional list we can use

and everything together

• Is this approach "comfortable" for your problem ? : Thread[bs -> {2, 4, 1, 1, 5, 2, 6, 2, 5, 2}] ? Oct 20, 2022 at 21:17
• Works. Comfortable. Thanks! Oct 20, 2022 at 21:18

However how to define the replacement from 2 lists?

bs = Array[b, 2];
as = Array[a, 2];