10x10 Array of Prime Numbers - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: 10x10 Array of Prime Numbers (/thread-12602.html) |
10x10 Array of Prime Numbers - smfox2 - Sep-02-2018 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: 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 RE: 10x10 Array of Prime Numbers - ichabod801 - Sep-03-2018 Use the reshape method of the array, with the dimensions you want as a tuple. |