You can see your current line width with
numpy.get_printoptions()['linewidth']
and set it with
numpy.set_printoptions(linewidth=160)
Automatically set printing width
If you’d like the terminal width to be set automatically, you can have Python execute a startup script. So create a file ~/.python_startup.py
or whatever you want to call it, with this inside it:
# Set the printing width to the current terminal width for NumPy.
#
# Note: if you change the terminal's width after starting Python,
# it will not update the printing width.
from os import getenv
terminal_width = getenv('COLUMNS')
try:
terminal_width = int(terminal_width)
except (ValueError, TypeError):
print('Sorry, I was unable to read your COLUMNS environment variable')
terminal_width = None
if terminal_width is not None and terminal_width > 0:
from numpy import set_printoptions
set_printoptions(linewidth = terminal_width)
del terminal_width
and to have Python execute this every time, open your ~/.bashrc
file, and add
# Instruct Python to execute a start up script
export PYTHONSTARTUP=$HOME/.python_startup.py
# Ensure that the startup script will be able to access COLUMNS
export COLUMNS