-2

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.

Tensor input to the concatenation method

Tensorflow error

George Pearse
  • 59
  • 1
  • 5

1 Answers1

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