Ellipsis in numpy array

Asked

Viewed 36 times

0

What the object means ... in a numpy array. I am working with a database and when I use the Unique method in one of the columns, between the objects it returns this ... What these reservations represent?

1 answer

1


He does not "return" .... When the array has a number of elements greater than a certain threshold (the default value is 1000) the numpy places ... just to say that it has more elements that it is not showing. For example

a = np.arange(10000)
print(a)

will display

array([   0,    1,    2, ..., 9997, 9998, 9999])

This array has 10000 elements and ... is not in the array.

You can see the threshold with the command

np.get_printoptions() 

that this shows

{'edgeitems': 3,
 'threshold': 1000,
 'floatmode': 'maxprec',
 'precision': 4,
 'suppress': False,
 'linewidth': 140,
 'nanstr': 'nan',
 'infstr': 'inf',
 'sign': '-',
 'formatter': None,
 'legacy': False}

You can display all the elements in a loop or change the threshold to something larger. For example, using np.set_printoptions(threshold=2000) then arrays with up to 2000 elements will be displayed without .... I think 1000 is a very sensible figure.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.