Python Forum
10x10 Array of Prime Numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
10x10 Array of Prime Numbers
#1
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
Reply
#2
Use the reshape method of the array, with the dimensions you want as a tuple.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,408 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 2,991 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Getting largest indices of array less than or equal to an array of numbers schniefen 5 2,624 Nov-02-2020, 08:14 PM
Last Post: schniefen
  Prime numbers janoshz 4 2,421 Oct-05-2019, 10:01 AM
Last Post: Preetimishra90
  How to Generate and Print An Array with Random Numbers in Python in the johnnynitro99293 14 9,575 Sep-20-2019, 11:56 AM
Last Post: ichabod801
  Prime numbers calculations frequency 3 2,978 Nov-27-2018, 07:07 PM
Last Post: micseydel
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,094 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE
  PRIME NUMBERS iamnotabot 6 4,593 Sep-17-2017, 04:25 PM
Last Post: iamnotabot
  prime factorization of two large numbers pyJim 2 3,676 Aug-24-2017, 03:19 PM
Last Post: pyJim

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020