<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def switch(self, time=None):
 """Obtain switch parameter, ie number of times the stage shifts."""

        stag_to_int = {'NREM1': 1, 'NREM2': 2, 'NREM3': 3, 'REM': 5, 'Wake': 0}
        hypno = [stag_to_int[x['stage']] for x in self.get_epochs(time=time) \
                 if x['stage'] in stag_to_int.keys()]
        
        return sum(asarray(diff(hypno), dtype=bool))