0%

some pytorch & python & linux tips

A cheatsheet for some common operations I may need to ask Google again and again…

Pytorch

Select rows based on conditions of column values

Basic idea is to use conditions to find all true index, and select the row/column based on index

For example, return rows whose column 1 value is exactly 2:

1
a[:,a[:, 0] == 2]

Another example is (selct rows whose column values are all larger than 0)

1
a[(a > 0).all(1)]