Repeating patterns in two dimensions

If you are given a 2x2 pattern such as

   1 0

   0 1

how can you build a larger pattern consisting of an arbitrary number of repetitions of the 2x2 pattern?

For example, let’s say you wanted to build a checkerboard pattern out of the pattern above, i.e.,

   1 0 1 0 1 0 1 0

   0 1 0 1 0 1 0 1

   1 0 1 0 1 0 1 0

   0 1 0 1 0 1 0 1

   1 0 1 0 1 0 1 0

   0 1 0 1 0 1 0 1

   1 0 1 0 1 0 1 0

   0 1 0 1 0 1 0 1

I’d like to think of this as building a 4x4 array of  1 0  but Q’s list orientation apparently won’t let me. So what is Q way to think of this problem?

                                                                      0 1

hi. 

See this post for more examples https://groups.google.com/forum/#!searchin/personal-kdbplus/matrix/personal-kdbplus/xHjIXPRuE8k/lNOnUCxHdjkJ

You can use Mohammad’s func to state the resulting x*y size.

Or you could use the below for your specific case..

{(y*count x)#(y*count x 0)#'x}[(1 0;0 1);4]

HTH,

Sean

q)t

1 0

0 1

q)f:{y#'y#x}

q)f[t;5]

1 0 1 0 1

0 1 0 1 0

1 0 1 0 1

0 1 0 1 0

1 0 1 0 1

q)f[t;8]

1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

q)f[t;10]

1 0 1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1 0 1