rougier/numpy-100

The solution to 49 doesn't work

shadowfishes opened this issue · 6 comments

I got an exception when running the 49th solution. The exception as follows:
ValueError: threshold must be numeric and non-NAN, try sys.maxsize for untruncated representation

Weird. It's still working for me using numpy 1.15.2. What is your version?

Yes, you're right. It's working well under numpy 1.15.2 . The exception is caused by numpy 1.16.3 which version I used in jupyter. So, it's a version problem. I think it may be better to assign the numpy version in requirements.txt.

I would be better if we find a solution that works on both version. Any idea?

I found the definition of threshold as follows:
threshold : int, optional
Total number of array elements which trigger summarization rather than full repr (default 1000).
Nan always represents that it's not a number, so the solution of 49th doesn't work well under numpy 1.16.3. I think we should use np.inf which indicate a infinite number instead, and it works on both versions. And there may be a flaw here, the threshold was set to 1000, so a (16,16) matrix couldn't trigger the summarization. A (32,32) matrix could demonstrate the problem well. So the solution should be as follows:
np.set_printoptions(threshold=np.inf)
Z = np.zeros((32,32))
print(Z)

Nice. Can you make a PR ?

Try float("inf") instead of np.nan.