3

The term "array-like" appears all over the sklearn documentation, and what that means is reasonably well defined here.

I have a situation where I have a dataset that will not fit in memory, but can be reasonably easily generated on-demand. As such, I would like to implement an "array-like" class that generates my data. However, it is not entirely clear what operations I should implement to make this work. Presumably I need __getitem__. Possibly also next and __iter__. How does one create an "array-like" class in python?

Him
  • 5,257
  • 3
  • 26
  • 83
  • What you need are Python's generators. They `yield` one element at a time. – Klaus D. Oct 09 '17 at 16:10
  • 1
    they are not array-like, because they are not random access – Him Oct 09 '17 at 16:12
  • I would be able to write an appropriate class. Mostly, I will need to pass this thing to a `.fit` method, and not have my computer explode. – Him Oct 09 '17 at 16:13
  • It looks like the source in most sklearn methods call `check_array` which does an `ndarray` conversion. This is going to be harder than I thought... – Him Oct 09 '17 at 16:21

0 Answers0