Is there any libraries functions (Scipy, Numpy, ?) that can double the array size by duplicating the values ? Like this :
[[1, 2, 4], [[1. 1. 2. 2. 4. 4.]
[5, 6, 2], -> [1. 1. 2. 2. 4. 4.]
[6, 7, 9]] [5. 5. 6. 6. 2. 2.]
[5. 5. 6. 6. 2. 2.]
[6. 6. 7. 7. 9. 9.]
[6. 6. 7. 7. 9. 9.]]
Or is there a faster way to do this operation ? When the array is very large, it becomes a problem. This is what I have so far.
def double_array(array):
nbr_rows, nbr_cols = array.shape
array_new = np.zeros((nbr_rows*2, nbr_cols*2))
for row in range(nbr_rows):
for col in range(nbr_cols):
array_new[row*2,col*2] = array[row,col]
array_new[row*2+1,col*2] = array[row,col]
array_new[row*2,col*2+1] = array[row,col]
array_new[row*2+1,col*2+1] = array[row,col]
return array_new
array = np.array([[1, 2, 4], [5, 6, 2], [6, 7, 9]])
array_new = double_array(array)
print(array_new)