[Question]
  [
**In:** Enough memory and a positive integer N
**Out:** N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by...
**Examples:**
1: `[1]` which is a 1D array (a list) of length 1, containing a single 1
2: `[[2,2],[2,2]]` which is a 2D array (a table) with 2 rows and 2 columns, filled with 2s
3: `[[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]]]` which is a 3D array (a cube) with 3 layers, 3 rows, and 3 columns, filled with 3s
4: `[[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]],[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]],[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]],[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]]]`
5 and 6: Please see one of the answers.
  
[Answer]
# [Python](https://docs.python.org/2/), 32 bytes
```
lambda n:eval('['*n+'n'+']*n'*n)
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQZ5ValpijoR6trpWnrZ6nrq0eq5UHZGv@T8svUkhWyMxTMNQx0jG24uIsKMrMK1FI00jW/A8A "Python 2 – TIO Nexus")
Makes a string like `"[[[n]*n]*n]*n"` with `n` multiplcations, and evaluates it as Python code. Since the evaluation happens within the function scope, the variable name `n` evaluates to the function input.
[Answer]
# J, 4 bytes
```
$~#~
```
[Try it online!](https://tio.run/nexus/j#@5@mYGuloFKnXMfFlZqcka@QpmD8/z8A "J – TIO Nexus")
## Explanation
```
$~#~  Input: integer n
  #~  Create n copies of n
$~    Shape n into an array with dimensions n copies of n
```
[Answer]
# [APL (Dyalog APL)](https://www.dyalog.com/), 4 bytes
```
⍴⍨⍴⊢
```
[Try it online!](https://tio.run/nexus/apl-dyalog#@5@m8KhtgsKj3i2PeleAyK5FXFyP@qaCRdMUDJHYRkhsYyS2yf//AA "APL (Dyalog APL) – TIO Nexus")
[Answer]
# Mathematica, ~~22~~ 20 bytes
```
(t=Table)@@t[#,#+1]&
(* or *)
Table@@Table[#,#+1]&
```
[Answer]
## JavaScript (ES6), ~~44~~ 40 bytes
```
f=(n,k=i=n)=>i--?f(n,Array(n).fill(k)):k
```
### Demo
```
f=(n,k=i=n)=>i--?f(n,Array(n).fill(k)):k
console.log(JSON.stringify(f(1)))
console.log(JSON.stringify(f(2)))
console.log(JSON.stringify(f(3)))
console.log(JSON.stringify(f(4)))
```
[Answer]
# Octave, ~~35~~ ~~33~~ ~~25~~ ~~23~~ 20 bytes
```
@(N)ones(N+!(1:N))*N
```
[Try it online!](https://tio.run/nexus/octave#@@@g4aeZn5darOGnrahhaOWnqanl9z8xr1jDWPM/AA "Octave – TIO Nexus")
```
@(N)ones(N*ones(1,N))*N
@(N)repmat(N,N*ones(1,N))
```
Thanks to @LuisMendo saved 8 bytes
```
@(N)ones(num2cell(!(1:N)+N){:})*N
```
[Try it online!](https://tio.run/nexus/octave#@@@g4aeZn5darJFXmmuUnJqTo6GoYWjlp6ntp1ltVaup5fc/Ma9Yw1jzPwA "Octave – TIO Nexus")
Previous answer:
```
@(N)repmat(N,num2cell(!(1:N)+N){:})
```
[Try it online!](https://tio.run/nexus/octave#@@@g4adZlFqQm1ii4aeTV5prlJyak6OhqGFo5aep7adZbVWr@T8xr1jDWPM/AA "Octave – TIO Nexus")
[Answer]
# R, 26
This is the obvious answer but perhaps there is something cleverer?
```
n=scan();array(n,rep(n,n))
```
[Answer]
# [Haskell](https://www.haskell.org/), 52 bytes
```
f n=iterate(filter(>'"').show.(<$[1..n]))(show n)!!n
```
[Try it online!](https://tio.run/nexus/haskell#FchBCoAgEAXQq3xDcGYzEG2zi0QLKSWhJiih41vuHu8MWeGRtcQ7rAUWCYI7hq0mqM@tS6SUj180uc6xPPv1Co127kV0YaYWUDZGax0@ "Haskell – TIO Nexus")
Inspired by [@nimi's answer](https://codegolf.stackexchange.com/a/111700), but using more predefined functions.
* Uses `iterate` and `!!` instead of a recursive help function.
* Instead of constructing list delimiters "by hand", uses `filter(>'"').show` to format a list of strings, then stripping away the extra `"` characters.
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), ~~6~~ 5 bytes
-1 thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
```
F¹.D)
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f7dBOPRfN//@NAQ "05AB1E (legacy) – Try It Online")
```
F     # For 0 .. input
 ¹.D) # Push <input> copies of the result of the last step as an array
```
[Answer]
## Haskell, 62 bytes
```
n#0=show n
n#l='[':tail((',':)=<<n#(l-1)<$[1..n])++"]"
f n=n#n
```
Usage example: `f 2` -> `"[[2,2],[2,2]]"`. [Try it online!](https://tio.run/nexus/haskell#FcqxDkAwFAXQ3Ve8qKRt0BCb9P0Bk1E6dBGSuoSKz68480kQDd/r8RIyiMByln30W1BKVrLXbC2ECnWrbTG3xsDpssxdni0EhkDa/QZi2v05kjqfOMVrgFk0/btzlD4 "Haskell – TIO Nexus").
Haskell's strict type system prevents a function that returns nested lists of different depths, so I construct the result as a string.
How it works:
```
n#l=                         n with the current level l is
    '[':                     a literal [ followed by
           n#(l-1)<$[1..n]   n copies of   n # (l-1)
        (',':)=<<            each prepended by a , and flattened into a single list
      tail                   and the first , removed
                  ++"]"      followed by a literal ]
n#0=show n                   the base case is n as a string
f n=n#n                      main function, start with level n         
```
[Answer]
# [Python 2](https://docs.python.org/2/), 36 bytes
-2 bytes thanks to @CalculatorFeline
```
a=n=input()
exec"a=[a]*n;"*n
print a
```
[Try it online!](https://tio.run/nexus/python2#@59om2ebmVdQWqKhyZVakZqslGgbnRirlWetpJX3v6AoM69EI1HzvwkA "Python 2 – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
⁾Wẋẋv
```
**[Try it online!](https://tio.run/nexus/jelly#@/@ocV/4w13dQFT2//9/EwA "Jelly – TIO Nexus")**
### How?
```
⁾Wẋẋv - Main link: n                            e.g.       3
⁾Wẋ   - character pair literal ['W','ẋ']                  "Wẋ"
   ẋ  - repeat list n times                               "WẋWẋWẋ"
    v - evaluate as Jelly code with input n          eval("WẋWẋWẋ", 3)
      - ...
        WẋWẋ... - toEval: n                e.g. 3
        W        - wrap                        [3]
         ẋ       - repeat list n times         [3,3,3]
          Wẋ     - wrap and repeat            [[3,3,3],[3,3,3],[3,3,3]]
            ...  - n times total             [[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]]]
         
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
R»µ¡
```
[Try it online!](https://tio.run/##y0rNyan8/z/o0O5DWw8t/P//vzEA "Jelly – Try It Online")
```
R»µ¡
R     Range. 2 -> [1, 2]
 »    Max between left arg and right arg. Vectorizes. -> [2, 2]
  µ   Separates into a new chain.
   ¡  Repeat 2 times. After another iteration this yields [[2, 2], [2, 2]].
```
Same thing but with a single monad and no need for the chain separator:
[**4 bytes**](https://tio.run/##y0rNyan8///Q7kdNaxIOLfz//78xAA)
```
»€`¡
```
[Answer]
# MATL, 8 bytes
```
ttY"l$l*
```
Try it at [**MATL Online**](https://matl.io/?code=ttY%222%24X%22%0A%0A%27Actual+Size%27yZy++++%25+Display+the+actual+size&inputs=4&version=19.8.0) (I have added some code showing the *actual* size of the output since all n-dimensional outputs in MATL are shown as 2D matrices where all dimensions > 2 are flattened into the second dimension).
**Explanation**
```
        % Implicitly grab the input (N)
tt      % Make two copies of N
Y"      % Perform run-length decoding to create N copies of N
l$1     % Create a matrix of ones that is this size  
*       % Multiply this matrix of ones by N
        % Implicitly display the result  
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 12 bytes
```
ri:X{aX*}X*p
```
[Try it online!](https://tio.run/nexus/cjam#@1@UaRVRnRihVRuhVfD/vzEA "CJam – TIO Nexus")
**Explanation**
```
ri:X          Read an integer from input, store it in X (leaves it on the stack)
    {   }X*   Execute this block X times:
     a          Wrap the top of stack in an array
      X*        Repeat the array X times
           p  Print nicely
```
[Answer]
# Java ~~97~~ ~~96~~ 95 bytes
```
Object c(int n,int i){Object[]a=new Object[n];for(int j=0;j<n;)a[j++]=i<2?n:c(n,i-1);return a;}
```
---
Ungolfed:
```
public class N_Dim {
    
    public static Object create(int n) {
        return create(n, n);
    }
        
    public static Object create(int n, int i) {
        Object[] array = new Object[n];
        for(int j=0;j<n;j++) {
            array[j] = i<2?n:create(n, i - 1);
        }
        return array;
    }
    public static void main(String[] args) {
        System.out.println(Arrays.deepToString((Object[]) create(3)));
    }
}
```
[Answer]
## JavaScript (ES6), 38 bytes
```
f=(n,m=n)=>m?Array(n).fill(f(n,m-1)):n
```
The memory-hungry version of this is 45 bytes:
```
f=(n,m=n)=>m?[...Array(n)].map(_=>f(n,m-1)):n
```
[Answer]
## Batch, 141 bytes
```
@set t=.
@for /l %%i in (2,1,%1)do @call set t=%%t%%,.
@set s=%1
@for /l %%i in (1,1,%1)do @call call set s=[%%%%t:.=%%s%%%%%%]
@echo %s%
```
Batch doesn't actually have arrays so this just prints the string representation of an array. Explanation: The first two lines build up a repeated pattern of `N` `.`s separated by `N-1` `,`s in the variable `t`. The fourth line then uses this as a substitution pattern `N` times to create the `N`-dimensional array. The double `call` is necessary because of how the `for` and `set` statements work. First, the `for` command substitutes variables. As it happens, all of my `%` signs are doubled, so this does nothing except to unquote them all, resulting in `call call set s=[%%t:.=%s%%%]`. It then repeats the resulting statement `N` times. Each time, the `call` command substitutes variables. At this point, the `s` variable only has a single set of `%`s, so it gets substituted, resulting in (e.g.) `call set s=[%t:.=[2,2]%]`. The inner call then substitutes the `t` variable, resulting in (e.g.) `set s=[[2,2],[2,2]]`, performing the desired assignment. The final value of `s` is then printed.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
Wẋ³µ¡
```
[Try it online!](https://tio.run/nexus/jelly#@x/@cFf3oc2Hth5a@P//fxMA "Jelly – TIO Nexus")
## Explanation
```
         Implicit input: N
   µ¡    Apply N times to input:
Wẋ³        “N copies of”
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~57~~ ~~53~~ ~~50~~ 38 bytes
```
f=lambda n,c=0:n-c and[f(n,c+1)*n]or 1
```
[Try it online!](https://tio.run/nexus/python3#@59mm5OYm5SSqJCnk2xrYJWnm6yQmJcSnaYB5GsbamrlxeYXKRj@z7PNzCvRyMwrKC3R0NTkKigCcYGKNDX/mwAA "Python 3 – TIO Nexus")
---
-4 bytes thanks to @CalculatorFeline
---
**34 bytes:**
```
f=lambda c,n:c and[f(c-1,n)*n]or 1
```
Needs to be called as `f(4,4)`
[Answer]
# Ruby, 28 26 bytes
*Thanks to [Cyoce](https://codegolf.stackexchange.com/users/41042/cyoce) for saving 2 bytes!*
```
->n{eval'['*n+'n'+']*n'*n}
```
Stolen shamelessly from [xnor](https://codegolf.stackexchange.com/users/20260/xnor)'s [excellent answer](https://codegolf.stackexchange.com/a/111696/58437).
[Answer]
## Ruby, 27 bytes
```
->a{(z=a).times{z=[z]*a};z}
```
Only 1 byte more but using a different approach instead of the 'eval' trick from xnor's wonderful Python answer.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + GNU utilities, 117 bytes
```
n=$[$1**$1]
seq -f$1o%.fd$n+1-p $n|dc|rev|sed -r "s/(0+|$[$1-1]*).*$/\1/;s/^(0*)/\1$1/;s/^1/[1]/"|tr \\n0$[$1-1] \ []
```
[Try it online!](https://tio.run/nexus/bash#LcsxDoMwDEDRvaewkJHAKDiWulU9SZIuTRhDm6BOvnsKgu3/4bX8RIdChBJuNX3BLChrPy8R8yTmA5g1vrWkn9YUwRToKg920kMZCTTOhOyFH5Vfg6VxbzxP2EngTrcC3md7AfDgQmvt/gc "Bash – TIO Nexus")
---
The program essentially counts from 0 to (n^n)-1 in base n, where n is the input. For each base-n number k in the count, it does the following:
1. If k ends with at least one digit 0, print a '[' for each digit 0 at the end of k.
2. Print n.
3. If k ends with at least one digit n-1, print a ']' for each digit n-1 at the end of k.
(The value n=1 needs to have brackets added as a special case. This input value also generates some output to stderr, which can be ignored under standard PPCG rules.)
Maybe there's a shorter way to implement this idea.
---
Sample run:
```
./array 3
[[[3 3 3] [3 3 3] [3 3 3]] [[3 3 3] [3 3 3] [3 3 3]] [[3 3 3] [3 3 3] [3 3 3]]]
```
[Answer]
# [Haskell](https://www.haskell.org/), 51 bytes
Other than the existing Haskell solutions this constructs a usable data type not just a string representation thereof (and is shorter):
```
data L=N[L]|E Int
f n=iterate(N.(<$[1..n]))(E n)!!n
```
[Try it online!](https://tio.run/##PYyxCoNAEET7@4oRUniFQiClVsEiIDZJJxZHXHNHzBruNmgg/24UQZiBea8Ya8KT@n6eWyMGZV7VZfMrcGFRHTh3Qt4IxVUaZ4f6mKbcaB0XYB1FPCcJbtYFLBm4/4KJWmrhOoyE0bBABry9W4cleAqfXpTjIIbvhKsdRpQYLXlSQFhx@Z40kG807brCFPSug1Iv43jh7T1Ft9STaZFnGR4k54GFWMJ8@gM "Haskell – Try It Online")
### Explanation / Ungolfed
The reason why this is an interesting challenge in Haskell is that a solution to this challenge needs to return different deeply nested lists and Haskell (without importing external modules) does not support this. One workaround which turned out to be the golfiest, is to define our own data type:
```
data NestedList = Nest [NestedList] | Entry Int
```
Now we can just define a function `f :: Int -> NestedList` which is able to represent all the required data types:
```
pow n = iterate (Nest . replicate n) (Entry n) !! n
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), ~~5~~ 4 bytes
```
_{a*
```
[Try it online!](https://tio.run/##y00syUjPz0n7/z@@OlHr/39DLiMuYy6T/wA "MathGolf – Try It Online")
## Explanation using `n = 2` (note that the outermost `[]` are not arrays, but are just there to show the stack)
```
_      duplicate TOS (stack is [2, 2])
 {     loop 2 times (stack is [2])
  a    wrap in array ([2] => [[2]], [[2, 2]] => [[[2, 2]]])
   *   pop a, b : push(a*b) ([[2]] => [[2, 2]], [[[2, 2]]] => [[[2, 2], [2, 2]]])
```
[Answer]
# [Raku](https://raku.org), 21 bytes
[try it online!](https://tio.run/##K0gtyjH7/786OrqiIlYBTKjEK1RUKBjH1mqkp5Zo6hUnVv7/bwQA)
```
{[[xx] [xx] $_ xx 3]}
```
[Answer]
# [Julia 0.6](http://julialang.org/), ~~23~~ 21 bytes
```
n->n>(n>n)...
> =fill
```
[Try it online!](https://tio.run/##yyrNyUw0@59m@z9P1y7PTiPPLk9TT0@Py07BNi0zJ@d/bmKBBlBGIyWzuCAnsVIjTSNPU9O6oCgzryQnT0NTU0dBw1DHWMdUU/M/AA "Julia 0.6 – Try It Online")
(Thanks to @MarcMush for -2 bytes.)
In Julia, binary operators are parsed as function calls, so `a>b` is `>(a, b)`, which here is `fill(a, b)`. So the above is really saying:
```
n->fill(n,fill(n,n)...)
```
The first argument to `fill` is the value to fill the new array with. The following arguments to that are the dimensions of the new array. Here we create those dimensions themselves using another `fill` call: we create an array of `n` `n`s, then splat that with `...` so that the first `fill`  call gets n number of dimension arguments, each with value n - so it creates an n-dimensional array where each dimension length is n, and filled with the value n.
[Answer]
# [Perl 6](https://perl6.org), 25 bytes
```
{($^n,{$_ xx$n}...*)[$n]}
```
Starts with `n`, and iteratively applies the "repeat n times" transformation `n` times, each time creating an additional level of `List` nesting.
[Try it online!](https://tio.run/nexus/perl6#y61UUEtTsP1fraESl6dTrRKvUFGhklerp6enpRmtkhdb@784sVIhTcHQmgvCMIIxjGEME@v/AA "Perl 6 – TIO Nexus")
[Answer]
# PHP, ~~70~~ 62 bytes
This is the simplest I can come up with.
```
for(;$i++<$n=$argv[1];)$F=array_fill(0,$n,$F?:$n);print_r($F);
```
Takes the input as the first argument and prints the resulting array on the screen.
---
Thanks to [@user59178](https://codegolf.stackexchange.com/users/59178/user59178) for saving me **8 bytes**!
[Answer]
# Clojure, 36 bytes
```
#(nth(iterate(fn[a](repeat % a))%)%)
```
Iterates function which repeats its argument `n` times, it produces infinite sequence of such elements and then takes its `n`th element. 
[See it online](https://ideone.com/l9pMOD) 
]