[IPython-User] How to configure/control line width?
Robert Kern
robert.kern@gmail....
Fri Mar 11 13:23:11 CST 2011
On 3/11/11 9:43 AM, Jorge Scandaliaris wrote:
> Hi all,
>
> Is there a way to configure ipython so when numpy arrays are displayed ipython
> would use all the available screen width?
>
> Ipython seems aware of screen width as doing:
>
> In [28]: print 'a'*200
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
IPython is not doing anything here. This is just your terminal wrapping the
single line being printed.
> uses the available width, but doing:
>
> In [32]: a = np.ones((5,20))
>
> In [33]: repr(a)
> Out[33]: 'array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
> 1.,\n 1., 1., 1., 1., 1., 1., 1.],\n [ 1., 1., 1., 1.,
> 1., 1., 1., 1., 1., 1., 1., 1., 1.,\n 1., 1., 1., 1., 1.,
> 1., 1.],\n [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
> 1.,\n 1., 1., 1., 1., 1., 1., 1.],\n [ 1., 1., 1., 1.,
> 1., 1., 1., 1., 1., 1., 1., 1., 1.,\n 1., 1., 1., 1., 1.,
> 1., 1.],\n [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
> 1.,\n 1., 1., 1., 1., 1., 1., 1.]])'
>
> does not. Is this behavior configurable/controllable?
See np.set_printoptions(). In the 0.11 branch of development, we have a
configurable printing system such that you could replace the printer for
nnumpy.ndarray instances. However, you will have to ask the terminal for how
wide it is, and this information is platform-specific, though not very difficult
to obtain. You can see how I do this in my personal IPython extensions:
https://bitbucket.org/robertkern/kernmagic/src/tip/kernmagic/utils.py
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the IPython-User
mailing list