I am new to tensorflow and I am following some online exercises to get familiar with tensorflow. I want to do the following task:
Create two tensors
xandyof shape 300 from any normal distribution. Usetf.cond()to return:
The mean squared error of
(x - y), if the average of all elements in(x - y)is negative.The sum of absolute value of all elements in the tensor
(x - y)otherwise.
My implementation:
x = tf.random_normal([300])
y = tf.random_normal([300])
mse = lambda: tf.losses.mean_squared_error(y, x)
absval = lambda: tf.abs(tf.subtract(x, y))
out = tf.cond(tf.less(x, y), mse, absval)
Error:
Shape must be rank 0 but is rank 1 for 'cond_1/Switch' (op: 'Switch') with input shapes: [300], [300]
Aucun commentaire:
Enregistrer un commentaire