Sep-02-2018, 07:56 PM
I am trying to construct a 10 by 10 array of prime numbers. I am able to construct an array of prime numbers but do not understand how to restrict the array to a 10 by 10.
Python Code:
Python Code:
import numpy as np import math def is_prime(n): if n % 2 == 0 and n > 2: return False return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2)) a = np.arange(1, 10**3), foo = np.vectorize(is_prime) pbools = foo(a) primes = np.extract(pbools, a) x = [[foo for i in range(10)] for j in range(10)] print(primes)Any help would be greatly appreciated