Coming from R to Python and I see why so many people love Python for data science. One useful feature of R is the quick subsetting. For example:
my_data = c(11,34,67,134,45,8,99,3543,1)
my_subset = c(3,8,1,6,4)
print(my_data[my_subset])
[1] 67 3543 11 8 134
One can programmatically generate subsets that satisfy various conditions and filter the data to that subset with a single instruction. How does one accomplish this in python?
arr = np.array([11,34,67,134,45,8,99,3543,1]); idx = np.array([3,8,1,6,4]); arr[idx-1]should do it, Output ->array([ 67, 3543, 11, 8, 134])