numpy-100 icon indicating copy to clipboard operation
numpy-100 copied to clipboard

The solution to 49 doesn't work

Open shadowfishes opened this issue 6 years ago • 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

shadowfishes avatar May 14 '19 08:05 shadowfishes

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

rougier avatar May 23 '19 16:05 rougier

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.

shadowfishes avatar May 24 '19 04:05 shadowfishes

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

rougier avatar May 24 '19 06:05 rougier

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)

shadowfishes avatar May 28 '19 06:05 shadowfishes

Nice. Can you make a PR ?

rougier avatar Jun 03 '19 08:06 rougier

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

iamyifan avatar Jun 27 '20 03:06 iamyifan