Skip to content Skip to sidebar Skip to footer

How To Set Max Output Width In Numpy?

I am using a Jupyter notebook. I have a pretty wide screen, but the displayed output (say, when I print a numpy array) is formatted as if the screen was narrow. I found a way of in

Solution 1:

I found this answer helpful in creating my own:

import numpy as np
np.set_printoptions(edgeitems=30, linewidth=100000, 
    formatter=dict(float=lambda x: "%.3g" % x))

The absurd linewidth means only edgeitems and the window's width will determine when newlines/wrapping occurs.

enter image description here

If I shrink the window a bit, it looks like this, so you may still need to play with the edgeitems or formatting:

enter image description here

Here are the docs for set_printoptions, of which the following are relevant:

  • edgeitems : Number of array items in summary at beginning and end of each dimension (default 3).

  • linewidth : The number of characters per line for the purpose of inserting line breaks (default 75).

Solution 2:

This is a year old now but maybe the answer will help someone else.

The way numpy-arrays are displayed depends on a number of things. With this code, you can show more items and use the full width of your screen:

This is the default

import numpy as np
np.set_printoptions(edgeitems=3)
np.core.arrayprint._line_width = 80

>>>array([[[0, 0, 0, ..., 0, 0, 0],>>>   [0, 0, 0, ..., 0, 0, 0],>>>   [0, 0, 0, ..., 0, 0, 0],>>>   ..., 

With the following code you increase the items shown at the edge of each array (start and end) as well as the line width:

import numpy as np
np.set_printoptions(edgeitems=10)
np.core.arrayprint._line_width = 180

>>>array([[[  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, ...,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],>>>        [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, ...,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],>>>        [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, ...,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],

Post a Comment for "How To Set Max Output Width In Numpy?"