1

I have an array A of matrices (or a 3-dim tensor) and I want to do the following:

Denote each matrix with a number, so A is [1,2,3,4,...,], and let's say that we have a window of length 3, I want to pass as input to a TensorFlow graph the 4-dim array [[1,2,3],[2,3,4],[3,4,5],....]. What's the most efficient way of doing this? (It's a bit like a convolution with a constant kernel, but without summing over the resulting matrices).

At the moment this is what I'm doing:

input_NN = [data[t, t + window] for t in range(my_range)]

and then I pass it to a TF placeholder.

Shall I think of a better way of doing it in numpy and pass the result to a placeholder or is there a fast way of doing this in TensorFlow by passing A directly?

Ziofil
  • 1,815
  • 1
  • 20
  • 30
  • Thank you for the pointers, but my question is wider than the "duplicates": I'm asking if it's possible to implement this in TensorFlow. – Ziofil Sep 12 '17 at 03:57
  • Reopened. Curious - Can you index into the first axis of input tensor with those sliding indices that could be computed with the broadcasting app from https://stackoverflow.com/a/40085052/? – Divakar Sep 12 '17 at 04:23
  • I'm giving it a go now – Ziofil Sep 12 '17 at 05:02
  • Yes we can, but it's not faster than a for loop (at least for my array dimensions) – Ziofil Sep 12 '17 at 05:36
  • 1
    Are you looking for [`tf.extract_image_patches`](https://www.tensorflow.org/api_docs/python/tf/extract_image_patches)? – Daniel F Sep 12 '17 at 06:30
  • @DanielF I used exactly that, works really well! – Ziofil Oct 10 '17 at 14:01

0 Answers0