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0 0 0 0 0 0 0
The only way for me to do this would be to do (X,'X),(X,'X) however, ideally I would like to construct a function so that I can chose how many times to replicate and tile the matrix, very similar to Matlab’s repmat function:
http://www.mathworks.co.uk/help/matlab/ref/repmat.html
Thanks,
Zak
use a combination of raze, enlist,rotate.
x:1 0 0 0 0 0 0 0 0 0
mmb:{[x;w;l]tils:-1*0+til count x;flip w#enlist raze l#enlist flip tils rotate:x}
mmb[x;2;2] take 2 x width and two x long
Thanks,
Sean
Thanks, that works well but what I wanted exactly was to transform X into newX from my question above.
I found what I wanted by deriving from your function
repandtile:{[data;w;l] flip w#enlist raze l#enlist flip data}
Thanks,
Zak
q)tile:{y#y#'x} / [input matrix; new size] q)show m:((1 0 0);(0 1 0);(0 0 1)) 1 0 0 0 1 0 0 0 1 q)tile[m;9] 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 q)tile[m;2] 1 0 0 1 q)tile[m;12] 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1
To: “personal-kdbplus@googlegroups.com”
Nice
Von meinem iPhone gesendet
> Am 12.05.2014 um 18:58 schrieb Mohammad Noor :
>
> q)tile:{y#y#'x} / [input matrix; new size]
> q)show m:((1 0 0);(0 1 0);(0 0 1))
> 1 0 0
> 0 1 0
> 0 0 1
> q)tile[m;9]
> 1 0 0 1 0 0 1 0 0
> 0 1 0 0 1 0 0 1 0
> 0 0 1 0 0 1 0 0 1
> 1 0 0 1 0 0 1 0 0
> 0 1 0 0 1 0 0 1 0
> 0 0 1 0 0 1 0 0 1
> 1 0 0 1 0 0 1 0 0
> 0 1 0 0 1 0 0 1 0
> 0 0 1 0 0 1 0 0 1
> q)tile[m;2]
> 1 0
> 0 1
> q)tile[m;12]
> 1 0 0 1 0 0 1 0 0 1 0 0
> 0 1 0 0 1 0 0 1 0 0 1 0
> 0 0 1 0 0 1 0 0 1 0 0 1
> 1 0 0 1 0 0 1 0 0 1 0 0
> 0 1 0 0 1 0 0 1 0 0 1 0
> 0 0 1 0 0 1 0 0 1 0 0 1
> 1 0 0 1 0 0 1 0 0 1 0 0
> 0 1 0 0 1 0 0 1 0 0 1 0
> 0 0 1 0 0 1 0 0 1 0 0 1
> 1 0 0 1 0 0 1 0 0 1 0 0
> 0 1 0 0 1 0 0 1 0 0 1 0
> 0 0 1 0 0 1 0 0 1 0 0 1
>
> –
>
Submitted via Google Groups
charset=“UTF-8”
X-Mailer: Microsoft Outlook 14.0
Thread-Index: AQGW+oKlIwfWMrRHNs/UNwyzWMAWigIRYGjWm54VZAA=
Content-Language: de
Here is a bad solution
q) m:3 cut 100010001b=20
q) \t tile1:{[m;n] n m:n:til[n] mod count m 0}[m;n:1000]
4j
q) \t tile:{y#y#'x}[m;n]
0j
q) tile1 ~ tile
1b
Don’t use it.
Kim
-----Urspr=C3=BCngliche Nachricht-----
Von: personal-kdbplus@googlegroups.com =
[mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Mohammad Noor
Gesendet: Montag, 12. Mai 2014 18:58
An: personal-kdbplus@googlegroups.com
Betreff: [personal kdb+] Replicate and tile array in kdb+
q)tile:{y#y#'x} / [input matrix; new size] q)show m:((1 0 0);(0 1 0);(0 =
0 1))
1 0 0
0 1 0
0 0 1
q)tile[m;9]
1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
q)tile[m;2]
1 0
0 1
q)tile[m;12]
1 0 0 1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1 0 0 1
1 0 0 1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1 0 0 1
1 0 0 1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1 0 0 1
1 0 0 1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1 0 0 1
–
You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
To unsubscribe from this group and stop receiving emails from it, send =
an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.