When I use ipython terminal
and want to print a numpy.ndarray
which has many columns, the lines are automatically broken somewhere around 80 characters (i.e. the width of the lines is cca 80 chars):
z = zeros((2,20))
print z
Presumably, ipython expects that my terminal has 80 columns. In fact however, my terminal has width of 176 characters and I would like to use the full width.
I have tried changing the following parameter, but this has no effect:
c.PlainTextFormatter.max_width = 160
How can I tell ipython
to use full width of my terminal ?
I am using ipython 1.2.1
on Debian Wheezy
You can see your current line width with
and set it with
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:and to have Python execute this every time, open your
~/.bashrc
file, and addAfter some digging through the code, it appears that the variable you're looking for is
numpy.core.arrayprint._line_width
, which is 75 by default. Setting it to 160 worked for me:The function used by default for array formatting is
numpy.core.numeric.array_repr
, although you can change this withnumpy.core.numeric.set_string_function
.To automatically resize both numpy and IPython whenever your window size changes, add the following to your
ipython_config.py
:If you want to delay loading numpy until necessary, look at Post import hooks in Python 3 for a solution.
If you're not using IPython, put the above in your PYTHONSTARTUP file and remove the IPython-specific lines.