Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipses when converting list of numpy arrays to string in python 3

I have a list of numpy arrays. I want to convert the list of arrays to a string. So that there will be a long string of arrays like '[ stuff ], [ stuff2 ]', etc. Each array has 192 elements. Conversion works when I do str(myList) if the list has 5 arrays or less. If it has 6 arrays, I get back truncated arrays with ellipses. Why is this? How can I stop it?.

I have examined the arrays themselves and they do not in fact contain ellipses, they contain the correct values.

I further looked into it and if I do something like str(myList[0:5]) it works on the first 5 arrays, but that 6th array always goes to ellipses. Note that this is not just ellipses when printing to screen either, I'm saving this variable and when I look at the saved text it has the ellipses.

like image 210
CHP Avatar asked Jan 31 '26 02:01

CHP


1 Answers

From a quick look, the only way is to use numpy.set_printoptions:

import numpy as np

a = np.random.randint(5, size=(6, 192))
s1 = str(a)
np.set_printoptions(threshold = np.prod(a.shape))
s2 = str(a)

print('...' in s1)
print('...' in s2)

gives

True
False

on my Ubuntu 14.04 system, Python 2.7, Numpy 1.8.2

I would restore the default to 1000 after changing it, and, in my opinion, the function numpy.array2string should have a threshold argument.

like image 146
Rory Yorke Avatar answered Feb 01 '26 16:02

Rory Yorke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!