Bottom Page

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?
Quote
#2
I suggest A = 2 * np.random.randint(-1, 1, [20, 20]) + 1
Quote
#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

Quote
#4
yeah that works thank you very much
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Check Array for numbers GloryHoleLover 7 305 Mar-02-2020, 07:08 PM
Last Post: micseydel
  output a list of random numbers 'x' columns wide adityavpratap 4 127 Jan-13-2020, 05:32 PM
Last Post: perfringo
  Can i prevent the random generator to generate already used numbers? MauserMan 3 190 Jan-05-2020, 04:44 PM
Last Post: MauserMan
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 295 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Working with Random Generated Numbers YoungGrassHopper 4 356 Sep-10-2019, 06:53 AM
Last Post: YoungGrassHopper
  class random var write to array storzo 5 378 Aug-02-2019, 03:26 PM
Last Post: storzo
  Need to generate random numbers Gateux 8 475 Jul-19-2019, 03:37 PM
Last Post: Man_from_India
  Division of an integer into sub-numbers Richard_SS 4 511 Jun-14-2019, 11:47 AM
Last Post: DeaD_EyE
  Generate unique random numbers from different lists Takeshio 5 514 May-24-2019, 07:29 PM
Last Post: ichabod801
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 418 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:


Users browsing this thread: 1 Guest(s)