Shubham Chowdhary Shubham Chowdhary - 4 months ago 29
Python Question

Using data from a file rather than random data in Tensorflow

I am trying to simulate Conway's Game of life in Tensorflow using python and have successfully implemented the code to simulate the game with a random initial 2d array using

tf.random_uniform(shape, minval=0, maxval=2, dtype=tf.int32)

Now I wish to initialize the 2d matrix with an array of 0s and 1s from a csv file having 0s and 1s in a 2d format.
How should I initialize the initial Board for the Conway's game??

My code till now:

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

X is my starting 2d array.


There are several ways, see below, for example:

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 =
    print X