Reputation: 1847
My problem is as follows:
When I want to divide a matrix by a vector in column axis, but TensorFlow only provides row division when A
is a matrix with [n,n]
shape and v
a vector with [1,n]
shape.
My solution was this:
tf.transpose(tf.div(tf.transpose(A), v))
I tried this but it doesn't works: Update: It Works! 🙂
tf.div(A, tf.transpose(v))
So my question is if exists more efficient solution for this problem.
Upvotes: 1
Views: 1970
Reputation: 222571
Your second solution with A / tf.transpose(v)
should work. tf.div() does not have an axis parameter because it "Divides x / y elementwise". So both tensors should have the same dimensions.
In your case it works with different dimensions because tf.div supports broadcasting. More about broadcasting is here.
Also it is as efficient as it could be, so no need to look for anything else.
Upvotes: 1