python - tensorflow gather across multiple dimentions -
gather(params, indices)
following
output[i, ..., j, :, ... :] = params[indices[i, ..., j], :, ..., :]
so if have 4-dimensional params , 2-dimensional indices, end having 5-dimensional array result
the question how do
output[i, ..., j, :, ... :] = params[indices[i, :], ..., indices[j, :], :, ..., :]
so acts numpy's
output = params[indices[0], indices[1], .. , :]
(the #206 ticket on github regarding different issue: numpy-like api, not gathering in general)
one possible way use gather_nd
, (as far understand) if want gather_nd
on not dimensions, still have create indices them, e.g. if have 10-dimensional array , want index first 2 dimensions 2-dimensional array b, a[b[0], b[1], :] our indices matrix have have 11 columns (with 8 redundant).
--- old indices ---- new index 0 0 <all rows of length 8> 0 1 1 <all rows of length 8> 1 ...
there's update on #206 @ebrevdo working on generalizing slicing.
meanwhile, flatten array, construct linear indices elements want, use gather, reshape back, done in another answer mrry. that's not worse in efficiency native implementation
Comments
Post a Comment