import numpy as np
import math
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
def fill_matrix_with_primes(rows, cols):
matrix = np.zeros((rows, cols), dtype=int)
num = 2
for i in range(rows):
for j in range(cols):
while not is_prime(num):
num += 1
matrix[i, j] = num
num += 1
return matrix
print(fill_matrix_with_primes(4, 5))
'''
run
[[ 2 3 5 7 11]
[13 17 19 23 29]
[31 37 41 43 47]
[53 59 61 67 71]]
'''