Numpy Display Options: Examples and Reference

Last updated:
Table of Contents

Version used: Numpy 1.18.1

Show full arrays

Arrays having more than threshold will get truncated.

import numpy as np

# default value is 1000
np.set_printoptions(threshold=2000)

np.array(range(5000))

before-set-printoptions By default, arrays with more
than 1000 elements get truncated
  
after-set-option After setting threshold to 2000,
all elements get printed

Show more edge items

edgeitems controls the number of elements shown when truncation is triggered

import numpy as np

# show 10 elements on either side
np.set_printoptions(edgeitems=5)

before-set-printoptions By default, truncated arrays show
3 elements at either side
  
after-set-printoptions After setting edgeitems to 5,
5 elements on either side
get printed

Set options temporarily

Use a with clause:

import numpy as np

with np.set_printoptions(edgeitems=5):
    # numpy code here uses the given
    # options

# other code is under default options

Dialogue & Discussion