Home > Software design >  how to convert tensorflow tensor to numpy array from given example?
how to convert tensorflow tensor to numpy array from given example?

Time:11-07

I am trying to compute Fast Fourier Transform (fft2d) but the following code provides the error:

print("type(pred[2]): ", type(pred[2]))
pred[2] = tf.make_ndarray(pred[2])
fft2_pre = np.fft.fft2(pred[2])

The error and output:

type(pred[2]):  <class 'tensorflow.python.framework.ops.Tensor'>
AttributeError: 'Tensor' object has no attribute 'tensor_shape'

how it could be solved?

CodePudding user response:

temp = tf.cast(pred[2], dtype=tf.complex64)
temp = tf.signal.fft(temp)
  • Related