Home > front end >  How to drop a row of a tensor tensor containing nan in TensorFlow
How to drop a row of a tensor tensor containing nan in TensorFlow

Time:09-25

I have a tensor:

tensor = tf.convert_to_tensor(np.array([[0, 1, 2, 3, 4, np.nan],
                                       [6, 7, 8, 9, 10, 11]]))

and would like to drop the row that has nan. For instance:

<tf.Tensor: shape=(6,), dtype=int64, numpy=array([ 6,  7,  8,  9, 10, 11])>

How do you do this in TensorFlow?

CodePudding user response:

This code will remove nan rows:

tensor[~np.isnan(tensor).any(axis=1)]
  • Related