stretch, scale, or double up an array with numpy?
I was wondering if there is a numpy function to "stretch" an array along a specific axis like the f开发者_开发技巧ollowing:
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]])
精彩评论