Skip to content

Instantly share code, notes, and snippets.

@rreece
Created March 11, 2020 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rreece/ce0fa3b769386d7828929171f38c849c to your computer and use it in GitHub Desktop.
Save rreece/ce0fa3b769386d7828929171f38c849c to your computer and use it in GitHub Desktop.
XLA-compatible version of tf.segment_mean
import tensorflow as tf
def segment_mean(x, bounds):
n = len(bounds)
segs = [
tf.reduce_mean(x[:,bounds[i]:bounds[i+1]], axis=1) for i in range(n-1)]
y = tf.stack(segs, axis=1)
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment