'how to convert to a tensor form a numpy array?

I tried to use the conver_to_tensor function

k = np.array([1,5,6,9,])
print(list(k))
k = list(k)
k = tf.convert_to_tensor(k)
k

Output:

[1, 5, 6, 9]
<tf.Tensor: shape=(4,), dtype=int32, numpy=array([1, 5, 6, 9], dtype=int32)>

Here i got it converted to a tensor but inside that it still contains in numpy array only. Is there way to completely convert to a tensor? basically i want a tensor to contain a list/array of numbers.



Solution 1:[1]

I assume this is what you are expecting to get:

k = np.array([1,5,6,9,])
print(tf.convert_to_tensor(k))  #(remove `list()` while converting to tensor)

Output:

tf.Tensor([1 5 6 9], shape=(4,), dtype=int64)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TFer2