Array representation in fastai

Hi !

I became used to fastai’s way to print arrays and wanted to transfer it to a project that doesn’t use fastai. But I can’t find where it is defined, I looked for a custom __repr__ or __str__ but can’t find it ? Does anyone know how it is coded ?

Which one do you like? Could you give us an example?

The one that look likes array([1, 2, 3, ..., 98, 99, 100]). But I’m actually noticing that it’s just numpy’s basic __repr__ for arrays that are too large. How would you modify numpyès __repr__ so that it changes for the whole library ? Do I need to create an imports module ?

EDIT: just discovered that we can use np.set_printoptions(threshold=n) to force numpy to use the ... representation when there are n elements or more in the array. Thats’s exactly what I want to set. For it to work accross the whole library, I guess I need to import numpy only once in an imports module and then use this ?

Yup, put it in your imports module and it should work.

1 Like