4

I have an intermediate model that outputs symmetric arrays. Those arrays are then used as input to another model. I'd like to just flatten the arrays and discard the lower triangles, since they're symmetric. Is there a best/most efficient way to do this?

Edit: I want the triangle extraction to be handled similar to any other Keras layer, so that the output of the first model can be input directly to the second model and trained end-to-end.

  • 1
    Possible duplicate of [extract upper/lower triangular part of a numpy matrix?](https://stackoverflow.com/questions/8905501/extract-upper-lower-triangular-part-of-a-numpy-matrix) – Joe Feb 27 '18 at 08:12

1 Answers1

2

Tensorflow and Keras use Numpy to handle the data. Consider using Numpy functions triu or triu_indices

peter.babic
  • 3,214
  • 3
  • 18
  • 31
Joe
  • 6,758
  • 2
  • 26
  • 47