在 Tensorflow 中使用文件中的数据而不是随机数据

Using data from a file rather than random data in Tensorflow

我正在尝试使用 python 在 Tensorflow 中模拟 Conway 的生命游戏,并且已经使用

成功实现了使用随机初始二维数组模拟游戏的代码
tf.random_uniform(shape, minval=0, maxval=2, dtype=tf.int32)

现在我想用一个包含 0 和 1 的 2d 格式的 csv 文件中的 0 和 1 数组来初始化 2d 矩阵。 我应该如何为康威游戏初始化初始棋盘?

到目前为止我的代码:

shape = (5,5)
initial_board = tf.random_uniform(shape, minval=0, maxval=2, dtype=tf.int32)
with tf.Session() as session:
    X = session.run(initial_board)

X 是我的起始二维数组。

有几种方式,见下例:

import tensorflow as tf

initial_board = tf.constant([[1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 0, 1, 0, 0], [1, 0, 0, 0, 1]], dtype=tf.int32)
with tf.Session() as session:
    X = session.run(initial_board)
    print X