10

It's word wrapping after 5 columns when there's enough space for all in one line. For example:

print array
==========================restart=========================================
([32235, 2323424, 2342342
3525324, 234234])
([234234, 23423, 543535,
76572, 23424])

Using python Idle, and I tried changing the initial window size preferences. The restart bar extends all the way across but not the numpy array ouput.

Can't seem to find the answer after searching around either. I'm sick and would really appreciate any help. Thanks!

2
  • 1
    I'm sorry, I can't replicate the issue (admittedly not using IDLE, which may be the issue). How is array defined? Commented Dec 8, 2012 at 4:30
  • It comes from a csv file turned into lists of lists and then into numpy array. I feel like the precision is set higher than the printarray usually allocates per cell. Numbers are about this long 5.22474679 5.18417234 Commented Dec 8, 2012 at 4:40

2 Answers 2

25

The actual answer to your question, which does not require sacrificing precision, is the following:

 import numpy as np
 large_width = 400
 np.set_printoptions(linewidth=large_width)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you from 2020~! I searched high and low for this and most answers were centred on increasing the width of the cell or widening the format, not increasing the number of columns in an array, which you have masterfully resolved.
4

Try using np.vectorize:

printer = np.vectorize(lambda x:'{0:5}'.format(x,))
print printer(b).astype(object)

Or try using np.set_printoptions:

Exactly as shown in IDLE:

>>> import numpy as np
>>> x=np.random.random(10)
>>> x
array([ 0.72239823,  0.69938461,  0.85466846,  0.03294278,  0.06698482,
        0.04137562,  0.4223521 ,  0.81317235,  0.62221494,  0.6205595 ])
>>> np.set_printoptions(precision=3)
>>> print(x)
[ 0.722  0.699  0.855  0.033  0.067  0.041  0.422  0.813  0.622  0.621]

1 Comment

Yep! Thank you! Sorry for taking a while I crashed afterwards. It was a good workaround, and I'm surprised it had that basically default issue with little documentation. Hope you have a great weekend!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.