Generalizing function from matrices to tensors

Hi everyone. This is my first post on this forum and I am relatively new to Tensorflow. As per the title, my overall goal is to generalize a function that works with regular numpy arrays to a function that works with tensors. The long term goal is to use this function as part of a custom loss function but that is a different topic.

From my own debugging sessions, I think my issue is that I do not know how to write the form exp^{ix} . Using numpy, I could do something like: np.exp(1j*x), where x is an array of reals. When I tried to do something similar for tensors, I get an error: TypeError: Cannot convert 1j to EagerTensor of dtype double.

Any comments and help is greatly appreciated! Thanks for your time.

PS: I tried to attach a Jupyter Notebook containing the code I am working with but it seems I am not allowed to do so. What’s the best way to share my code and any relevant files needed to run it?

Do you mean something like:

import tensorflow as tf
x = tf.constant([2.0, 8.0],dtype=tf.complex64)


Yes, that worked! I checked further upstream in my code and I had to use tf.cast(x, dtype=tf.complex64) to cast other variables to complex as well. Thanks!