ZHANG Juenjie
ZHANG Juenjie

Reputation: 531

How to convert a numpy array of tensors to a tensor?

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?

Upvotes: 1

Views: 1218

Answers (1)

Maxim
Maxim

Reputation: 53758

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.

Upvotes: 1

Related Questions