目标从2开始。从给定的数组中获取输入,目标是下一个要整形的element.Due,直到12个输入到来。我需要将输入重塑为形状数组(批次数为2,2,3),其中批数数为len(文本)//(2*2*3),以便输入批数:批数为1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
[
# First Batch
[
# Batch of Input
[[ 1 2 3], [ 7 8 9]],
# Batch of targets
[[ 2 3 4], [ 8 9 10]]
],
# Second Batch
[
# Batch of Input
[[ 4 5 6], [10 11 12]],
# Batch of targets
[[ 5 6 7], [11 12 13]]
]
]目标从2开始。从给定的数组中获取输入,在12个输入到来之前,目标是其下一个要整形的element.Due。我需要将输入重塑为形状数组(批次数,2,2,3),其中批数数为len(文本)//(2*2*3),因此输入的数量将为:批次数*2*2*3
发布于 2017-06-04 12:20:43
您可以使用strides
from numpy.lib.stride_tricks import as_strided as strided
a = np.arange(1, 16)
a
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])s = a.strides[0]
strided(a, (2, 2, 2, 3), (s * 3, s, s * 6, s))
array([[[[ 1, 2, 3],
[ 7, 8, 9]],
[[ 2, 3, 4],
[ 8, 9, 10]]],
[[[ 4, 5, 6],
[10, 11, 12]],
[[ 5, 6, 7],
[11, 12, 13]]]])https://stackoverflow.com/questions/44350583
复制相似问题