5
$\begingroup$

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.

$\endgroup$

1 Answer 1

7
$\begingroup$

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
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.