lst1=[ ] lst2=[ ] import numpy as np n=3 m=3 mat=np.random.randint(10, size=(n,m)) print(mat) for i in range(n): for j in range(m): for a in range(2, mat[i][j]): if mat[i][j]%a!=0: lst2.append(mat[i][j]) break print(lst2)
See the answer in your original post, of which, this is a duplicate.
Please, lock/close this thread.