numpy sometimes found in Python

Revision en1, by dotsdog, 2024-09-06 23:39:04

I thought to play with Python (which I use for work) and solve the last contest.

For problem C I wrote a very simple code:

import numpy as np
for _ in range(int(input())):
    x, y, k = map(int, input().split())
    tx = int(np.ceil(x/k))
    ty = int(np.ceil(y/k))
    ans = 2*tx - 1 if tx > ty else 2*ty
    print(ans)

Which PyPy 3.10 refused to compile (ModuleNotFoundError: No module named 'numpy'). A bit strange, but ok.

Surely Python 3.8 should have numpy (how can one live without?!), and indeed, that got compiled and gave correct answers. But it was a bit slow (155 ms for 3 test cases), so I wanted to see if just importing the module costs so much time. So I tried to compile the following code:

import numpy as np
for _ in range(int(input())):
    x, y, k = map(int, input().split())
    tx = 0#int(np.ceil(x/k))
    ty = 0#int(np.ceil(y/k))
    ans = 2*tx - 1 if tx > ty else 2*ty
    print(ans)

... which refused to compile (in the same Python 3.8!) claiming that... "ModuleNotFoundError: No module named 'numpy'"!

How could that be possible?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English dotsdog 2024-09-06 23:39:04 1202 Initial revision (published)