I want to achieve this:
a = np.array ([[1, 2],
[2, 1]])
b = np.array ([[0.25, 0.25, 0.5, 0.5],
[0.25, 0.25, 0.5, 0.5],
[0.5, 0.5, 0.25, 0.25],
[0.5, 0.5, 0.25, 0.25])
Mathematically they r not the same matrices. But i think you get the idea what i want to do. I want to double the dimension of a matrix. But therefore i want to keep the information from the initial matrix a by take the quarter for the four corresponding cells.
Does some1 knows how to do this efficiently in numpy?
You can use two repeat functions over both axis and then a simple division:
In [8]: np.repeat(np.repeat(a, 2, 1), 2, 0)/4
Out[8]:
array([[0.25, 0.25, 0.5 , 0.5 ],
[0.25, 0.25, 0.5 , 0.5 ],
[0.5 , 0.5 , 0.25, 0.25],
[0.5 , 0.5 , 0.25, 0.25]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With