I would like to convert a Tensorflow tensor into a numpy array. My code looks as follows:
t = tf.gather_nd(angle, [1,1]) # extract row 1, column 1 element of angle tensor
t = t.numpy() # convert tensor t to numpy array
which results in:
AttributeError: 'Tensor' object has no attribute 'numpy'
I've tried different things that are proposed here, like trying out different Tensorflow versions (2.0,2.2,2.7) and triggering eager execution with tf.compat.v1.enable_eager_execution() or tf.enable_eager_execution() but the error message remains. I have used Python 3.7 on all Tensorflow versions.
Has anyone faced a similar issue? Im running out of ideas on this one.
What does the
angleparameter consist of? You can try again by upgrading your existingTensorFlowin your system which will upgrade thenumpyversion also.It seems there is no problem with
tf.gather_nd()api.Suppose,
Output:
After converting this
tensortonumpy:Output: