【发布时间】:2021-03-15 05:48:11
【问题描述】:
我有一个函数
def multivariate_data(dataset, target, start_index, end_index, history_size,
target_size, step, single_step=False):
data = []
labels = []
start_index = start_index + history_size
if end_index is None:
end_index = len(dataset) - target_size
#print(history_size)
for i in range(start_index, end_index):
indices = range(i-history_size, i, step)
data.append(dataset[indices])
if single_step:
labels.append(target[i+target_size])
else:
labels.append(target[i:i+target_size])
return np.array(data), np.array(labels)
我想在 GPU 上进行计算。但只有张量运算可以在 GPU 上运行。所以我需要重写我的函数。 for 循环必须更改为 tf.while_loop。 我所有的 numpy 数组都必须更改为张量。 如何将我的函数和 for 循环重写为 tf.while_loop?
【问题讨论】:
标签: python-3.x numpy tensorflow tensorflow2.0 nested-loops