[Question]
  [
Given a description of the base state of a recursive ASCII pattern, output an expanded state somewhere along the recursion steps.
More specifically: Let the following be an example:
```
##..
##..
..__
..__
```
Where `#` is filled, `.` is empty, and `_` is recursive.
This describes a pattern wherein the top left quarter is filled, the top right and bottom left are empty, and the bottom right repeats the current pattern.
More rigorously, the pattern is a grid containing some number of `#`, `.`, and `_`. The grid will always be rectangular, and there will be at least one `_` and all `_` will be in a rectangular sub-grid such that the overall grid's `(width, height)` is an integer multiple of the sub-grid's `(width, height)`.
Your task is, given such a pattern and a number of steps, build up an expanded form of this pattern. That is, each step, expand the grid by `n` times (where `n` is the ratio between the recursive sub-grid and the overall grid), and fill the `_` sub-grid with the pattern. At the end, fill the base-state `_` all with `#` or `.` - you choose which, but it must all be the same, and it must be consistently one or the other no matter the input.
To be VERY rigorous, `f(g, n)` where `f` is this challenge, `g` is the pattern grid, and `n` is the number of steps, then `f(g, 0) == g` (with the `_` replaced by `#` OR `.`), and `f(g, n)` is the grid scaled up by `r ** n` times (where `r` is the ratio of the pattern to the recursive sub-grid), with `_` replaced by `f(g, n - 1)`.
Let's do an example:
```
#.
._
3
```
At 0 steps, the grid is this:
```
#.
._
```
At 1 step, the grid is this:
```
##..
##..
..#.
..._
```
At 2 steps, the grid is this:
```
####....
####....
####....
####....
....##..
....##..
......#.
......._
```
At 3 steps, the grid is this:
```
########........
########........
########........
########........
########........
########........
########........
########........
........####....
........####....
........####....
........####....
............##..
............##..
..............#.
..............._
```
Then, your output can either replace the `_` with `.` or `#`, but again, all `_` must become the same in the final output, and you must always fill it with `.` or `#` no matter the input.
# Examples
The `_` are shown in this output - you are to replace them with `#` or `.`, by choice. They are simply shown as `_` just to reduce confusion as to where the `_` were and where pre-filled `#` and `.` are meant to be.
```
#.#.
.__#
#__.
.#.#
2
```
becomes
```
####....####....
####....####....
####....####....
####....####....
....##..##..####
....##..##..####
......#.#.######
.......__#######
#######__.......
######.#.#......
####..##..##....
####..##..##....
....####....####
....####....####
....####....####
....####....####
```
(Just gonna put this out there - this is NOT what I thought it would look like AT ALL)
A non-square non-double example:
```
##.
##.
##.
##.
.#_
.#_
2
```
becomes
```
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
##################.........
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........###############...
.........#########...#####.
.........#########...#####.
.........#########...#####.
.........#########...#####.
.........#########...###.#_
.........#########...###.#_
```
Last example.
```
#__#
.##.
3
```
becomes
```
###############__###############
##############.##.##############
############..####..############
############..####..############
########....########....########
########....########....########
########....########....########
########....########....########
........################........
........################........
........################........
........################........
........################........
........################........
........################........
........################........
```
# Rules and Specifications
Input requires a grid and an integer. This grid can be taken in any reasonable, convenient format, and you can replace the characters with any three consistent, distinct values. These can be integers too, for example.
Output requires a grid. This grid can be given in any reasonable, convenient format, and you can replace the characters with any two consistent, distinct values. These do not have to be the same as the ones corresponding to the inputs (why???).
Standard loopholes apply.
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge, so the shortest program in bytes for each language wins. No answer will be accepted.
Happy golfing!
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~33~~ ~~30~~ ~~27~~ 26 bytes
```
ii:"l1G1=aYm/t&Y"1Gy1=(]Zc
```
Input is a numerical matrix with `0` for empty, `9` for filled and `1` for recursive.
Replaces recursive by filled at the end.
Output is a character matrix with   (space) for empty and `#` for filled.
[Try it online!](https://tio.run/##y00syfn/PzPTSinH0N3QNjEyV79ELVLJ0L3S0FYjNir5//9oSwUDBSC2BlKGQGhpDeSBGGARsGQslxEA) Or [verify all test cases](https://tio.run/##y00syfmf8D8z00opx9Dd0DYxMle/RC1SydC90tBWIzYq@b9BcoRLVEXI/2hLBQMFILYGUoZAaGkN5IEYYBGwZCyXERdQGVgRVgqkzhBKQRVDjTKAKInlMgYA).
### Explanation
```
i      % Take first input: matrix, M. This will be grown recursively
i      % Take second input: number, n
:      % Range [1 2 ... n]
"      % For each
  l    %   Push 1
  1G   %   Push first input, M
  1=   %   Compare with 1
  a    %   Any. This gives a vector with 1 for columns that contain
       %   at least a 1 in input M, and 0 otherwise
  Ym   %   Mean. This gives the proportion of columns with 1
  /    %   Divide 1 by that. This gives the ratio r referred to in the challenge
  t    %   Duplicate
  &Y"  %   Repeat elements. This enlarges the current matrix by r along each dimension
  1G   %   Push input M again
  y    %   Puesh a copy of the current enlarged matrix
  1=   %   Compare with 1. Gives a logical mask
  (    %   Write M into the positions indicated by that mask
]      % End
Zc     % Convert nonzeros to character '#' and zeros to space. Implicitly display
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~32~~ 28 bytes
```
³,Z¬ÆmṀ$€İḞ¤xZ¥ƒYṣ0ż³F¤FỴµ¡!
```
[Try it online!](https://tio.run/##AVQAq/9qZWxsef//wrMsWsKsw4Zt4bmAJOKCrMSw4biewqR4WsKlxpJZ4bmjMMW8wrNGwqRG4bu0wrXCoSH/w4dZ//9bMSwwLDAsMV0sWzIsMSwxLDJd/zM "Jelly – Try It Online")
A full program that takes two arguments, a matrix of integers (0-2) and the number of steps and returns a matrix of integers (1-2). 0 is used for the recursive bit. 
Thanks to @JonathanAllan for saving two bytes!
## Explanation (outdated)
```
                           µ¡ | Repeat the following the number of times indicates by the right argument
             ¤                | - Following as a nilad:
³                             |   - Original left argument (matrix of integers)
 ,Z                           |   - Paired with itself transposed
           Ɗ€                 |   - For each of the pair, do the following as a monad:
   ¬                          |     - Not
    ẸƇ                        |     - Keep only those with any True values
      F                       |     - Flatten
          Ɗ                   |     - Following as a monad:
       L                      |       - Length
        :                     |       - Divided by (integer)
         S                    |       - Sum
                ¥ƒ            | - Reduce using the argument to this iteration as the initial argument and the following as a dyad:
              x               |   - Repeat that many times
               Z              |   - Transpose
                  Y           | Join with newlines
                   ṣ0         | - Split at zeros
                     ż  ¤     | - Zip with the following as a nilad:
                      ³       | - Original left argument
                       F      | - Flattened
                         F    | - Flatten
                          Ỵ   | - Split at newlines
                             !| Factorial (0 becomes 1)
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~250~~ ~~249~~ ~~280~~ ~~266~~ ~~250~~ 248 bytes
```
def f(p,n):
 s=p;Q=L(p[0])
 for z in R(n):u,y=[(Q/r.count('_'),y)for y,r in enumerate(s)if'_'in r][0];s=[''.join(s[j/u][i/u]for i in R(u*L(s[0]))).replace('_'*Q,p[(j-y*u)%L(p)])for j in R(u*L(s))]
 return[c.replace('_','#')for c in s]
R=range;L=len
```
[Try it online!](https://tio.run/##ZZFLbsMgEIbX5RRIVgUTUdI4WSXiBtkkW4qsyMUpVooRNgv38u5gK1IkL4aB@b95AGEcfjpfTtO3bWjDg/BwJLRX4XRRZx70pwFCmy7SP@o8vXKUkxiV5pdtlHWX/MBZxUCMkKFRxIxZn35tvA2W9@Aa1DEWDdY69UozJtvOed7rdpuMdrjkVLfUT5szKtgVQEYbHrfa5gabiwiatx/jJsE7zgVm7te@JAEYQqMdUvS6fs0VrGAzXWe6N@Sq4s3f7emsHtZPYacYY4UkskIv@/BweKcvz4CQUC7arFYFKaoKd3hek/uZRPDVZFFlW9OHmc4lJXIrPU@LX5Hn1TzsxB4ED6Uos9sv7oBBcyRvITo/0Jy3PGuAZ8yvxeWDn8T0Dw "Python 2 – Try It Online")
Input and output are both lists of strings.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 35 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
Ê/Uèø0
NÌÆ=c@VÇXmpV r0@NÎ¬gT°
®r0Q
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=CsovVej4MApOzMY9Y0BWx1htcFYgcjBATs6sZ1SwCq5yMFE&input=WyciLicsJy4wJ10KMAotUg)
]