I have a 1x1 EagerTensor object that I'm trying to convert to a single float value. i.e.
tf.Tensor([[-0.04473801]], shape=(1, 1), dtype=float32) -> -0.04473801
There seemed to be a simple answer that I've used on other tensors in the past - just use the item() method a la this answer. However, when I try to use the .item() method on an EagerTensor object, I get the following error:
AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'item'
Why is this happening? Do EagerTensors not have the item() method? One workaround I've found is using float(tensor_variable.numpy()[0])
, but it seems like there should be a better way.