Background
I have one 1D NumPy array initialized with zeros.
import numpy as np
section = np.zeros(1000)
Then I have a Pandas DataFrame, where I have indexes in two columns:
d= {'start': {0: 7200, 1: 7500, 2: 7560, 3: 8100, 4: 11400},
'end': {0: 10800, 1: 8100, 2: 8100, 3: 8150, 4: 12000}}
df = pd.DataFrame(data=d, columns=['start', 'end'])
For each pair of indices, I want to set the value of the corresponding indices in the numpy array to True.
My current solution
I can do this by applying a function to a DataFrame:
def fill_array(row):
section[row.start:row.end] = True
df.apply(fill_array, axis=1)
I want to vectorize this operation
This works as I expect, but for the pleasure of it I would like to do a vector operation. I do not really understand this, and my search on the Internet did not set me on the right path.
I would really appreciate any suggestions on how to do this in a vector operation, if at all possible.