Convert a list of tensor to list of all elements of tensors? - tensorflow2.0

I have a list of tensors and i want to convert it in a list of all elements of tensors. The dtype of elements is strings.
Any help is appreciated.

Related

Numpy Changing Matrix dimensions

I have a 28x28 pixel image as a numpy array and its shape is (28,28) using the np.array.shape function. I want the shape to be 784x1. In other words with a NxN matrix how do you convert it to a N^2x1. Using the flatten function i get almost what I'm looking for, the shape from flatten is (784,).
Another possible way is to use np.atleast_2d
np.atleast_2d(arr.flatten())

Is there a differentiable way to cast a tensor into int64?

I'm creating a layer which uses its input tensors to create a SparseTensor, i.e., the input tensors are the respective indices and values of the SparseTensor.
Since:
indices: A 2-D int64 tensor of shape
And because tf.cast(x, tf.int64) is not differentiable, I'm not sure if this is achievable.
Another option is to find a turnaround based on tf.round(), but SparseTensor won't accept a different type of tensor as indices.
Is there a way to cast a tensor to integer and not having None for gradient ?
How can I create a SparseTensor using previous layers outputs, which are float tensors ?

tensorflow: deal with variable length tensors

I'm into a situation that I need to transform things like
[[1,2,3,-1]
[1,2,-1,-1]
[1,-1,-1,-1]]
into
[[1,2,3]
[1,2]
[1]]
for which -1 are paddings that I need to remove, I have tried map_fn, but it needs each unpacked tensor to have same shape after the process, I tried while loop in TF, but also the loop vars need to be tensors, and a list with variable length tensors can not be passed in, how can achieve this simple function?

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?
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.

index rows from 2D tensor

Suppose I have a 2D tensor A of floats, and a 1D tensor B of ints. The numbers in B represent indices to the rows of A. How do I efficiently perform a lookup of this indices inside a tensorflow graph?
Have you already tried tf.gather() ?
See also this question: TensorFlow: using a tensor to index another tensor