I am trying to double the size of a matrix without changing the values. Is there any dedicated function to do that? Here, I need to convert the matrix a to matrix b.
a = np.array([[1,2],
[3,4]])
b = np.array([[1,1,2,2],
[1,1,2,2],
[3,3,4,4],
[3,3,4,4]])
CodePudding user response:
You can repeat
on both axes:
a = np.array([[1, 2],
[3, 4]])
b =np.repeat(np.repeat(a, 2, axis=0), 2, axis=1)
Output:
array([[1, 1, 2, 2],
[1, 1, 2, 2],
[3, 3, 4, 4],
[3, 3, 4, 4]])