Quantcast
Channel: How to pick top q elements in each row and each column in a Tensorflow tensor? - Stack Overflow
Browsing latest articles
Browse All 2 View Live

Answer by Stewart_R for How to pick top q elements in each row and each...

TLDR; We can create a function that masks all but the top k elements row wise as follows: def mask_all_but_top_k(X, k): n = X.shape[1] top_k_indices = tf.math.top_k(X, k).indices mask =...

View Article


How to pick top q elements in each row and each column in a Tensorflow tensor?

I am implementing a special loss function in Tensorflow. Here is the numpy-style code of a special function which picks top q elements and masks other elements in each row and each column. Note that A...

View Article

Browsing latest articles
Browse All 2 View Live


Latest Images