diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2015-06-12 14:55:07 +0200 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2015-06-12 14:55:07 +0200 |
commit | d6462d271aeaf1be635cbc7c4317ae6a3b30b63f (patch) | |
tree | 2280fb876ae6082e608020af31c15e16ce67412b /pyspike/SpikeTrain.py | |
parent | 2b957ac5d7c964b6fe0e99bb078a396732331869 (diff) |
implement __getitem__ and __len__ for SpikeTrain
This allows to use SpikeTrain objects to be used in many applications as if
they were arrays with spike times.
Diffstat (limited to 'pyspike/SpikeTrain.py')
-rw-r--r-- | pyspike/SpikeTrain.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pyspike/SpikeTrain.py b/pyspike/SpikeTrain.py index 9127b60..4b59a5d 100644 --- a/pyspike/SpikeTrain.py +++ b/pyspike/SpikeTrain.py @@ -32,6 +32,21 @@ class SpikeTrain(object): self.t_start = 0.0 self.t_end = float(edges) + def __getitem__(self, index): + """ Returns the time of the spike given by index. + + :param index: Index of the spike. + :return: spike time. + """ + return self.spikes[index] + + def __len__(self): + """ Returns the number of spikes. + + :return: Number of spikes. + """ + return len(self.spikes) + def sort(self): """ Sorts the spike times of this spike train using `np.sort` """ |