-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_store.py
More file actions
36 lines (27 loc) · 1.28 KB
/
data_store.py
File metadata and controls
36 lines (27 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# !/usr/bin/env python
# ****************************************** Libraries to be imported ****************************************** #
import random
import numpy as np
# ****************************************** Class Declaration Start ****************************************** #
class DataStore(object):
def __init__(self, max_memory=50000):
self._max_memory = max_memory
self._samples = []
# ****************************** Class Method Declaration ****************************************** #
def add_sample(self, sample):
self._samples.append(sample)
while len(self._samples) > self._max_memory:
self._samples.pop(0)
# ****************************** Class Method Declaration ****************************************** #
def sample(self, no_samples):
if no_samples > len(self._samples):
return np.array(random.sample(self._samples, len(self._samples)))
else:
return np.array(random.sample(self._samples, no_samples))
# ****************************************** Class Declaration End ****************************************** #
"""
Author: Yash Bansod
UID: 116776547
E-mail: yashb@umd.edu
Organisation: University of Maryland, College Park
"""