1

I have a numpy array list something like the follows:

a=np.array([tf.convert_to_tensor(1),tf.convert_to_tensor(2)])

I want to convert this list into a tensor. My real list is not like the constant example but some complex tensor, so does anyone know how to do this?

1 Answer 1

1

I assume all of the tensors have the same shape. Then you can just call tf.stack:

>>> print(tf.stack([tf.convert_to_tensor(1), tf.convert_to_tensor(2)]))
Tensor("stack:0", shape=(2,), dtype=int32)

Note that it accepts the list, not numpy array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.