Elegant way to get the length of a dataset


I am stuck on a small problem here. In exercise 6, it is required to get the length of a dataset. There are many ways to do so, as is in this post. However, it seems that the original dataset is infinite as we repeat it. For this reason, I am not sure how to proceed. Any help is welcome.


The dataset itself is not infinite it is finite, it just repeats i.e. drawing more and more examples as we go on.

1 Like

@gent.spah Yeah. That is what I mean. I have tried many methods mentioned in the post operating on the training_dataset. However, as you have commented, it usually tells me the dataset is infinite. Are there any methods to overcome this?

You should try the len() of the python list.

1 Like

@gent.spah Do you mind if I try to give you the notebook? Because that is the first method I tried and it says it has run out of memory…

This is probably because you are using the dataset coming out of the repeat function…you need to use the one (the original) before it becomes repeated over and over again.


That is what I am actually trying to avoid since I guess I will have to download the data again. However, if that is the case, then that is the case. I will try now and see what will happen.

@gent.spah I think that solves everything. So I will mark that as solution.