Issue
This Content is from Stack Overflow. Question asked by Galen
Is there an analog to numpy.delete
where I could just delete a row or column from a 2-mode tensor?
Unlike the following answers that filter by the content of the array
- Removing certain rows from tensor in tensorflow without using tf.RaggedTensor
- How to delete rows in a tensor with tensorflow?
I want to simply delete certain rows and columns by providing indices.
Solution
Use the tensorflow boolean_mask
operation:
import tensorflow as tf
a = tf.constant([1,9,2,8,3,7,4,6,5])
b = tf.boolean_mask(a,tf.greater(5,a))
with tf.Session() as sess:
print(sess.run(b)) #[1,2,3,4]
This Question was asked in StackOverflow by David and Answered by Him It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.