I need a Matrix{UInt8}, P, of 0 and 1 which exhibits chess board patterns
of submatrices A of size(A)=(5,5).
I defined it as follows:
P=zeros(UInt8, 100,100)
A= fill(UInt8(1), (5,5))
for k in 0:2:18
for j in 0:2:18
P[5k+1:5k+5, 5j+1:5j+5] .=A
end
end
for k in 1:2:19
for j in 1:2:19
P[5k+1:5k+5, 5j+1:5j+5] .=A
end
end
Though not memory efficient, you could do it easily with the Kronecker Product.
Create a regular chess pattern and multiply it by a matrix of ones of the size of the block you want.
O(s)=ones(Bool,s,s)
mb(n,m)=[(i+j)%2==0 for i in 1:n, j in 1:m]
mb(m,n)=reduce(hcat,accumulate(xor, fill(true,m),init=i) for i in accumulate(xor,fill(true,n)))
blockm(s,m,n)=hvcat(ntuple(_->n,m),mb(n,m).*[O(s)]...)
Simple enough to fix, just add 1 to the argument of mod. I thought demonstrating the principle was meaningful even without spending too long parsing the example.