首页 > 解决方案 > 如何在 Tensorflow 中使用张量生成数据集

问题描述

我需要一种数据集类型的张量,shape=[160000, 1, 2],我想生成如下组合,但是从 0 到 400

[[[0 0]]

[[0 1]]

[[0 2]]

[[0 3]]

[[1 0]]

[[1 1]]

[[1 2]]

[[1 3]]

[[2 0]]

[[2 1]]

[[2 2]]

[[2 3]]]

标签: pythonnumpytensorflow

解决方案


首先创建一个numpy数组并使用它创建张量。以下代码输出shape = [160000, 1, 2]每个值之间的张量0 to 400

import numpy as np
import tensorflow as tf
arr = np.random.random_integers(low=0, high=400, size=(160000, 1, 2))
tensor = tf.constant(arr)

推荐阅读