Issue
Given a 2-dimensional tensor t
, what's the fastest way to compute a tensor h
where
h[i, :] = tf.histogram_fixed_width(t[i, :], vals, nbins)
I.e. where tf.histogram_fixed_width
is called per row of the input tensor t
?
It seems that tf.histogram_fixed_width
is missing an axis
parameter that works like, e.g., tf.reduce_sum
's axis
parameter.
Solution
Inspired by keveman's answer and because the number of rows of t
is fixed and rather small, I chose to use a combination of tf.gather
to split rows and tf.pack
to join rows. It looks simple and works, will see if it is efficient...
t_histo_rows = [
tf.histogram_fixed_width(
tf.gather(t, [row]),
vals, nbins)
for row in range(t_num_rows)]
t_histo = tf.pack(t_histo_rows, axis=0)
Answered By - fabian789
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.