python - 如何在 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]]]
解决方案
首先创建一个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)
推荐阅读
- python - 在连体 CNN 上使用 .fit_generator 时出错
- php - 将 php 字符串放入 html 文件中,同时使用 file_get_contents 回显?
- python - 在每次迭代中更新一个 pandas 数据框并附加到上一个
- c++ - 使用 g++-9 设置堆栈大小无效
- docker - Wiil docker update 命令会停止容器吗?
- python - 第一个非零结果按位与python
- python - AttributeError:模块'tensorflow._api.v2.train'没有属性'AdamOptimizer
- python - Python - 列表过滤
- java - 读取子 Firebase 数据库的值
- javascript - 嵌套异步函数中的 setState - React Hooks