I noticed something while debugging a Python program in Pycharm. I work with a large numpy 1D array of shape (n,)
. When looking at it via the variables tab in the PyCharm debugger, the values are displayed in a big row, space separated, but for every 18 values, there is a comma. I joined a picture of the debugger's output, but it just shows what I just said - at least I think it shows this:
This happens when debugging the following code snippet:
import numpy as np
a = np.full((19,), 10.0)
b = [ 10.0 for x in range(19)]
# line to be able to see a and b in the debugger before the end of the program
print()
The used version is Pycharm 2023.2.1.
If I look at a Python array of the same size, the separator is a coma and is used consistently in the whole array. I cannot test it on another computer to see if this is related to how it is stored in my memory.
My question is, why does this comma appear?
It appears to be related to how the variables are printed. If you run print(a)
, you will have a line break after 18 values. print(b)
will simply print everything on a single line.
You can change the behavior of numpy by setting the linewidth, e.g. to infinite as follows:
np.set_printoptions(linewidth=np.inf)
This will change the appearance a
in the PyCharm debugger with the commas now removed.