Reputation: 361
How do I convert a matrix A
A = [a b c
d e f
g h i]
To matrix B?
B = [a a b b c c
a a b b c c
d d e e f f
d d e e f f
g g h h i i
g g h h i i]
Upvotes: 3
Views: 121
Reputation: 71
It's slightly slower than repeat
, but for a numeric array, you can also use kron
:
julia> A = permutedims(reshape(1:9, 3, 3))
3×3 Matrix{Int64}:
1 2 3
4 5 6
7 8 9
julia> kron(A, ones(Int, 2, 2))
6×6 Matrix{Int64}:
1 1 2 2 3 3
1 1 2 2 3 3
4 4 5 5 6 6
4 4 5 5 6 6
7 7 8 8 9 9
7 7 8 8 9 9
Upvotes: 1
Reputation: 13800
You can use repeat
:
julia> A = ['a' 'b' 'c'
'd' 'e' 'f'
'g' 'h' 'i']
3×3 Matrix{Char}:
'a' 'b' 'c'
'd' 'e' 'f'
'g' 'h' 'i'
julia> repeat(A, inner = (2, 2))
6×6 Matrix{Char}:
'a' 'a' 'b' 'b' 'c' 'c'
'a' 'a' 'b' 'b' 'c' 'c'
'd' 'd' 'e' 'e' 'f' 'f'
'd' 'd' 'e' 'e' 'f' 'f'
'g' 'g' 'h' 'h' 'i' 'i'
'g' 'g' 'h' 'h' 'i' 'i'
Upvotes: 6