import numpy as np
print(mat) for i in range(n):
for j in range(m):
for a in range(2, mat[i][j]):
First of all, you should create meaningful variable names. For instance, what are lst1 and lst2? Wouldn't it make more sense to call them primes and compounds?
Your test for primes is logically incorrect. What you do is this:
A correct (but not the most efficient) way to test for prime would be like this (your loop conditions are correct: for a in range(2, mat[i][j]))
I hope this helps.
Good luck with the implementation!