On Sat, May 7, 2022, at 11:36, Ilya Kamenshchikov wrote:
> Hello,
>
> I wanted to discuss a pain point I've experienced while debugging numpy 
> code. When dealing with e.g. transformed image arrays or other 
> non-trivial ndarrays in debugger, I'm swamped by a bunch of numbers in 
> their repr that don't help me at all. What I really care about is 
> *shape and dtype*, as they are essentially what distinguishes complete 
> type of numpy arrays.

Hi Ilya,

It sounds like you're not actually looking for the repr when you are debugging. 
If you just need the shape and dtype, why not just print those?

Even "mere" debuggers like pdb support command aliases, see e.g. 
https://docs.python.org/3/library/pdb.html#pdbcommand-alias . I'm sure any 
debugger or IDE worth its salt will let you define a helper function in some 
configuration file which you can use during debugging to print what you need.

AndrĂ¡s

>
> Example of not helpful output:
> ```
> array([[[0.49113064, 0.42102904, 0.62108876],
>         [0.25435884, 0.18665439, 0.53790145],
> ```
>
> By counting the [ brackets, I can at least get the number of 
> dimensions, but usefulness stops here.
>
> Could repr of an array start with something like:
> `array(*shape=[32,32,3], dtype=float, data=*([[[0.49113064, ...)`
>
> I know one invariant that repr likes to keep is that you can post repr 
> and it should be the initialisation of the represented object, but 
> given that we replace long number sequence with ..., this is already 
> not the case.
>
> Short term: Perhaps a plugin / change to IDE could do what I ask, 
> please let me know if something like this already exists :)
>
> Long term: I think that behavior will be more useful than what is 
> currently there. It could also be conditionally there once we anyhow 
> need to use ... for too long arrays.
>
> Best Regards,
> --
> Ilya Kamen
> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: deak.and...@gmail.com
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to