开发者

stretch, scale, or double up an array with numpy?

开发者 https://www.devze.com 2023-04-09 05:48 出处:网络
I was wondering if there is a numpy function to \"stretch\" an array along a specific axis like the f开发者_开发技巧ollowing:

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

精彩评论

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

关注公众号