You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

normal_data.py 713 B

3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132
  1. import numpy as np
  2. class NormalIterator:
  3. def __init__(self, num_of_data=1000):
  4. self._num_of_data = num_of_data
  5. self._data = list(range(num_of_data))
  6. self._index = 0
  7. def __iter__(self):
  8. return self
  9. def __next__(self):
  10. if self._index >= self._num_of_data:
  11. raise StopIteration
  12. _data = self._data[self._index]
  13. self._index += 1
  14. return self._data
  15. def __len__(self):
  16. return self._num_of_data
  17. class RandomDataset:
  18. def __init__(self, num_data=10):
  19. self.data = np.random.rand(num_data)
  20. def __len__(self):
  21. return len(self.data)
  22. def __getitem__(self, item):
  23. return self.data[item]