I'm trying to carry out one-hot encoding with the tensorflow API. To do so you need to specify the number of distinct values up front so I've had to iterate through each variable and count the distinct values in each case. This leaves me with a one-hot encoded tensor for each variable that I want to join back together. Each has the same size in one dimension and a different size in the other (dependent on the number of distinct values). I now want to concatenate them back into one along the axis with matching sizes. However, the tensorflow concat method appears to require that they match size in both dimensions. Do I have to revert back to pandas / numpy to achieve this? Feels like it should be a simple task.
Asked
Active
Viewed 548 times
-2
-
1Please do give the code samples – Trect Oct 31 '20 at 19:10
1 Answers
2
Axis should be 1 instead of 0:
import tensorflow as tf
x = tf.random.uniform([100, 100])
y = tf.random.uniform([100, 2])
z = tf.concat((x, y), 1)

Andrey
- 5,932
- 3
- 17
- 35
-
Amazing! Really thought I'd already tried that but thanks so much, was about to give up on that task. – George Pearse Oct 31 '20 at 13:52