I'd like to generate integer vectors in $\{-M,-M+1,\dots,M\}^n$, where $M$ and $n$ are parameters. For a fixed $n$, say $n=3$ for instance, I only know I can use
Flatten[Table[{i, j, k}, {i, -M, M}, {j, -M, M}, {k, -M, M}]]
to get the list. But for larger $n$, I would have to add more coordinate ranges manually. Is there an automatic way to do this?
I have a similar question on Sum
and NSum
; for instance, I want to compute $\sum_x e^{-\|x\|^2}$ for $x$ over $\{-M,\dots,M\}^n$. For $n=3$ I could write
NSum[E^(-(i^2 + j^2 + z^2)), {i, -M, M}, {j, -M, M}, {k, -M, M}]
Is there a more automatic way to do this?