I have a matrix $M$, whose dimension I am unsure of, which has only $\lbrace0,1\rbrace$ entries. I would like to generate all the possible matrices that result from changing (some subset) of the $1$'s to $-1$'s. For example, if $M=\lbrace\lbrace0,1\rbrace,\lbrace 1,0\rbrace\rbrace$, then I would like to generate the list: $$ \lbrace\lbrace\lbrace0,1\rbrace,\lbrace 1,0\rbrace\rbrace,\lbrace\lbrace0,-1\rbrace,\lbrace 1,0\rbrace\rbrace,\lbrace\lbrace0,1\rbrace,\lbrace -1,0\rbrace\rbrace,\lbrace\lbrace0,-1\rbrace,\lbrace -1,0\rbrace\rbrace\rbrace.$$
I am trying to use ReplaceList to do this, but it is not working out exactly as I would want. For example, here is an example for a 2x2 matrix:
ReplaceList[{1, 1, 1, 1},
{{x___, 1, y___} -> {x, -1, y},
{z___, 1, x___, 1, y___} -> {z, -1, x, -1, y},
{t___, 1, z___, 1, x___, 1, y___} -> {t, -1, z, -1, x, -1, y},
{1, 1, 1, 1} -> {-1, -1, -1, -1}}]
Not exactly extensible (nor very pretty). Is there a nice way to do this? Again, I would like to have code that works regardless of dimension, and also accepts as input a matrix (you might notice I Flattened my 2x2 above), and returns a list of matrices.
Thanks!
