4
$\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$
6
$\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
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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