I was wondering if there is a numpy function to "stretch" an array along a specific axis like the following:
a =[[1,2,3,4],[1,2,3,4]]
to
a = [[1,1,2,2,3,3,4,4],[1,1,2,2,3,3,4,4]]
Thanks in advance!
import numpy as np
a = np.array([[1,2,3,4],[1,2,3,4]])
First possibility:
a.repeat(2, axis=1)
or the second:
np.kron(a, [1,1])
Both returning:
array([[1, 1, 2, 2, 3, 3, 4, 4],
[1, 1, 2, 2, 3, 3, 4, 4]])
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