dashnick
dashnick

Reputation: 2060

Find maximum absolute scalar value in list of tensors

I have a list of tensors, with different dimensions. I want to find the maximum absolute scalar value of all the tensors. Trouble is, I think I need a way to do greater than or less than on tensors, but I can only find tf.equal(). This is the kind of thing I'd like to do:

curMaxAbs = tf.Variable(-1, tf.float64)
for g in myList:
    maxG = tf.abs(tf.reduce_max(g))
    minG = tf.abs(tf.reduce_min(g))
    maxAbsG = maxG if tf.greaterThan(maxG,minG) else minG
    curMaxAbs = maxAbsG if tf.greaterThan(maxAbsG, curMaxAbs) else curMaxAbs

Of course there doesn't seem to be a tf.greaterThan() function. Obviously this would be trivial if I could use tf.eval() and convert to numpy arrays but unfortunately I need to do this during construction.

Upvotes: 0

Views: 454

Answers (1)

Peter Szoldan
Peter Szoldan

Reputation: 4868

How about tf.maximum like this:

maxAbsG = tf.maximum ( maxG, minG )

Upvotes: 1

Related Questions