开发者

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]])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜