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.

1
  • Sounds like your list of arrays is really a 2d array. numpy uses ellipses when arrays get larger than a 1000 elements (hence the 5 v 6). If it was really a list of arrays, it would format each one independently, and not use ellipses. Commented Sep 27, 2015 at 16:28

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.