Transforming input feature
本帖最后由 fantomas 于 2018-10-13 09:08 编辑I'm trying to transform an input feature in my input pipeline.It has the shape where 1 means at that position is a black stone, -1 means white stone and 0 means empty space.I also have a feature with shape indicating which players turn it is at every step. Again 1 means it is blacks turn and -1 for white.I want to transform the input feature into a tensor with shape adding 3 binary feature planes.The 1st plane is saving the current players stones, the 2nd plane the enemy players stones and the 3rd plane being all 1 if it is blacks turn else 0.I know how to accomplish this in numpy but have no idea how to do it in tensorflow since the array ops are not in place. Is it even possible to accomplish what I want to do?This is my numpy code:import numpy as npnp.random.seed(230)
positions = np.random.random_integers(-1, 1, [3, 9, 9])
print("Position raw shape: {}".format(positions.shape))
to_play = np.random.random_integers(0, 1, [3])
to_play[to_play == 0 = -1
print("\nOrder of players\n{}".format(to_play))
black_moves = to_play == 1
print("\nBlack positions raw:\n{}".format(positions[black_moves]))
black_moves_black_stones = positions[black_moves == 1
black_moves_white_stones = positions[black_moves == -1
white_moves = to_play == -1
print("\nWhite positions raw:\n{}".format(positions[white_moves]))
white_moves_white_stones = positions[white_moves == -1
white_moves_black_stones = positions[white_moves == 1
result = np.zeros([3, 3, 9, 9])
result[black_moves, 0 = np.where(black_moves_black_stones, 1, 0)
result[black_moves, 1 = np.where(black_moves_white_stones, 1, 0)
result[black_moves, 2 = 1
print("\nPositions when the player is black\n{}".format(result[black_moves]))
result[white_moves, 0 = np.where(white_moves_white_stones, 1, 0)
result[white_moves, 1 = np.where(white_moves_black_stones, 1, 0)
result[white_moves, 2 = 0
print("\nPositions when the player is white\n{}".format(result[white_moves]))
页:
[1]