My code :
def entropy(x):
return tf.convert_to_tensor(skimage.measure_shannon_entropy(np.array(x)))
def calc_entropy(x, fn):
i = tf.constant(0)
while_condition = lambda i: tf.less(i, fn)
#loop
r = tf.while_loop(while_condition, entropy, x[0, :, :, i])
return r
a = tf.constant([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]) # shape=(1, 2, 2, 2)
output = calc_entropy(a, 2)
Output : [1.23, 0.12]
But my code is showing this error : ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()