Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does tf.gather_nd intuitively do?

Tags:

tensorflow

Can you intuitively explain or give more examples about tf.gather_nd for indexing and slicing into high-dimensional tensors in Tensorflow?

I read the API, but it is kept quite concise that I find myself hard to follow the function's concept.

like image 803
thanhtang Avatar asked Mar 05 '17 12:03

thanhtang


People also ask

What does TF Gather_nd do?

tf. gather_nd is an extension of tf. gather in the sense that it allows you to not only access the 1st dimension of a tensor, but potentially all of them.

What does the axis parameter of TF Expand_dims do?

expand_dims() is used to insert an addition dimension in input Tensor. Parameters: input: It is the input Tensor. axis: It defines the index at which dimension should be inserted.

What is TF Where?

tf. where will return the indices of condition that are non-zero, in the form of a 2-D tensor with shape [n, d] , where n is the number of non-zero elements in condition ( tf. count_nonzero(condition) ), and d is the number of axes of condition ( tf. rank(condition) ).

Is TF gather differentiable?

It's only differentiable w.r.t. self. y but not the integer/discrete elements of self. actions_array.


Video Answer


1 Answers

Ok, so think about it like this:

You are providing a list of index values to index the provided tensor to get those slices. The first dimension of the indices you provide is for each index you will perform. Let's pretend that tensor is just a list of lists.

[[0]] means you want to get one specific slice(list) at index 0 in the provided tensor. Just like this:

[tensor[0]] 

[[0], [1]] means you want get two specific slices at indices 0 and 1 like this:

[tensor[0], tensor[1]] 

Now what if tensor is more than one dimensions? We do the same thing:

[[0, 0]] means you want to get one slice at index [0,0] of the 0-th list. Like this:

[tensor[0][0]] 

[[0, 1], [2, 3]] means you want return two slices at the indices and dimensions provided. Like this:

[tensor[0][1], tensor[2][3]] 

I hope that makes sense. I tried using Python indexing to help explain how it would look in Python to do this to a list of lists.

like image 192
Max Weinzierl Avatar answered Nov 10 '22 09:11

Max Weinzierl