[英]numpy.tile for 3d array
I have to get 3D array demension (4, 2, 1) from two value (60, 80) 我必须从两个值(60,80)中获得3D数组尺寸(4,2,1)
import numpy as np
array([[[ 60.],
[ 60.]],
[[ 60.],
[ 60.]],
[[ 80.],
[ 80.]],
[[ 80.],
[ 80.]]])
I do as below 我做如下
a = np.array([[[ 60.]],
[[ 80.]]])
np.tile(a, (2, 2,1))
and get 并得到
array([[[ 60.],
[ 60.]],
[[ 80.],
[ 80.]],
[[ 60.],
[ 60.]],
[[ 80.],
[ 80.]]])
How to get the expected array? 如何获得期望的数组?
You might use combined np.tile
with np.repeat
: 您可以结合使用
np.tile
和np.repeat
:
a = np.array([[[ 60.]],
[[ 80.]]])
np.repeat(np.tile(a, (1,2,1)), 2, axis=0)
#array([[[ 60.],
# [ 60.]],
# [[ 60.],
# [ 60.]],
# [[ 80.],
# [ 80.]],
# [[ 80.],
# [ 80.]]])
Or use np.repeat
+ reshape
: 或者使用
np.repeat
+ reshape
:
np.repeat(a, 4).reshape(4,2,1)
#array([[[ 60.],
# [ 60.]],
# [[ 60.],
# [ 60.]],
# [[ 80.],
# [ 80.]],
# [[ 80.],
# [ 80.]]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.