Shubham Chowdhary - 3 months ago 24

Python Question

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 = session.run(initial_board)

X is my starting 2d array.

Answer

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 = session.run(initial_board)
print X
```