Python Forum
20 x 20 Integer array with random numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
20 x 20 Integer array with random numbers
#1
How do I make a 20 x 20 array and fill it with random 1s and -1s ? I've tried using A=np.random.randint(-1,1,[20,20])
print(A)
but this includes zeros in the array. So how do I make an array without any zeros?
Reply
#2
I suggest A = 2 * np.random.randint(-1, 1, [20, 20]) + 1
Reply
#3
Use np.random.choice. Pass it an array of -1 and 1 and the size.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
yeah that works thank you very much
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  random numbers, randint janeik 2 527 Nov-27-2023, 05:17 PM
Last Post: janeik
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,028 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,534 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,454 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  convert array of numbers to byte array adetheheat 3 2,732 Aug-13-2020, 05:09 PM
Last Post: bowlofred
  Check Array for numbers GloryHoleLover 7 3,228 Mar-02-2020, 07:08 PM
Last Post: micseydel
  output a list of random numbers 'x' columns wide adityavpratap 4 2,924 Jan-13-2020, 05:32 PM
Last Post: perfringo
  Can i prevent the random generator to generate already used numbers? MauserMan 3 2,809 Jan-05-2020, 04:44 PM
Last Post: MauserMan
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,367 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Working with Random Generated Numbers YoungGrassHopper 4 3,138 Sep-10-2019, 06:53 AM
Last Post: YoungGrassHopper

Forum Jump:

User Panel Messages

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