5

I have a big list of the form

list={P[1,1],..,P[i,j]}

and would like to assign 0 to each of them, but

list=ConstantArray[0,Length[list]]

doesn't work. While it does work for lists that aren't indexed the way I have them... I tried doing a Do loop but with the size of the list it's extremely slow.

Karsten7
  • 27,448
  • 5
  • 73
  • 134
Gehaktmolen
  • 151
  • 2

1 Answers1

7

You could use

Evaluate[list] = ConstantArray[0, Length[list]]

or

MapThread[Set, {list, ConstantArray[0, Length[list]]}]

to Set each indexed variable inside of list to 0.

If the indexes for the variables inside list follow a known condition, one can use for example

p[i_ /; i < 3, j_ /; j < 5] = 0

or memorization

p[i_ /; i < 3, j_ /; j < 5] := p[i, j] = 0
Karsten7
  • 27,448
  • 5
  • 73
  • 134