I wish this help you Is there a general function to build a matrix from smaller blocks, i.e. build matrix , Here are some base R solutions. Maybe you can use code :
M < rbind(cbind(A,B),cbind(C,D))
u < list(list(A,B),list(C,D))
M < do.call(rbind,Map(function(x) do.call(cbind,x),u))
A < matrix(1:4,nrow = 2)
B < matrix(1:6,nrow = 2)
C < matrix(1:6,ncol = 2)
D < matrix(1:9,nrow = 3)
> M
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 1 3 5
[2,] 2 4 2 4 6
[3,] 1 4 1 4 7
[4,] 2 5 2 5 8
[5,] 3 6 3 6 9
Share :

Split a matrix into smaller matrices
By : user6718461
Date : March 29 2020, 07:55 AM
hop of those help? I have a matrix of size 20*20. I want to split it into two submatrices of size 20*10. If i use the following code: , do the following code :
f = mat2cell( e, 20, [10 10] );

Create a larger matrix from smaller matrices in numpy
By : Mehdi Majidi
Date : March 29 2020, 07:55 AM
hop of those help? I have 3 matrices A,B,C. I wish to create a larger matrix of the form , This: code :
numpy.bmat([[numpy.zeros(appropriate_shape), A], [B, C]])

Algorithm to create a square matrix given any number of smaller square matrices
By : rng
Date : March 29 2020, 07:55 AM
it helps some times I will want to plot some images using Opencv, and for this I would like to glue images together. , Here's a snippet that I use for doing this sort of thing: code :
import numpy as np
def montage(imgarray, nrows=None, border=5, border_val=np.nan):
"""
Returns an array of regularly spaced images in a regular grid, separated
by a border
imgarray:
3D array of 2D images (n_images, rows, cols)
nrows:
the number of rows of images in the output array. if
unspecified, nrows = ceil(sqrt(n_images))
border:
the border size separating images (px)
border_val:
the value of the border regions of the output array (np.nan
renders as transparent with imshow)
"""
dims = (imgarray.shape[0], imgarray.shape[1]+2*border,
imgarray.shape[2] + 2*border)
X = np.ones(dims, dtype=imgarray.dtype) * border_val
X[:,border:border,border:border] = imgarray
# array dims should be [imageno,r,c]
count, m, n = X.shape
if nrows != None:
mm = nrows
nn = int(np.ceil(count/nrows))
else:
mm = int(np.ceil(np.sqrt(count)))
nn = mm
M = np.ones((nn * n, mm * m)) * np.nan
image_id = 0
for j in xrange(mm):
for k in xrange(nn):
if image_id >= count:
break
sliceM, sliceN = j * m, k * n
img = X[image_id,:, :].T
M[sliceN:(sliceN + n), sliceM:(sliceM + m)] = img
image_id += 1
return np.flipud(np.rot90(M))
from scipy.misc import lena
from matplotlib import pyplot as plt
img = lena().astype(np.float32)
img = img.min()
img /= img.max()
imgarray = np.sin(np.linspace(0, 2*np.pi, 25)[:, None, None] + img)
m = montage(imgarray)
plt.imshow(m, cmap=plt.cm.jet)

How can I create a matrix based on smaller matrices?
By : Giuseppe Diciolla
Date : March 29 2020, 07:55 AM

Numpy: create a matrix from smaller matrices
By : user33362
Date : March 29 2020, 07:55 AM
will be helpful for those in need We can use NumPy's Kronecker product  code :
np.kron(np.ones((2, 2), dtype=int), m)
In [140]: m
Out[140]:
array([[1, 2],
[3, 4]])
In [141]: np.kron(np.ones((2, 2), dtype=int), m)
Out[141]:
array([[1, 2, 1, 2],
[3, 4, 3, 4],
[1, 2, 1, 2],
[3, 4, 3, 4]])

