Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 20 x 20 Integer array with random numbers harryk Unladen Swallow Posts: 2 Threads: 1 Joined: Jul 2018 Reputation: 0 Likes received: 0 #1 Jul-28-2018, 03:30 PM 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? Gribouillis Posts: 2,260 Threads: 24 Joined: Jan 2018 Reputation: 214 Likes received: 545 #2 Jul-28-2018, 03:37 PM I suggest `A = 2 * np.random.randint(-1, 1, [20, 20]) + 1` ichabod801 Bunny Rabbit Posts: 4,231 Threads: 94 Joined: Sep 2016 Reputation: 271 Likes received: 1262 #3 Jul-28-2018, 03:37 PM 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 harryk Unladen Swallow Posts: 2 Threads: 1 Joined: Jul 2018 Reputation: 0 Likes received: 0 #4 Jul-28-2018, 03:38 PM yeah that works thank you very much « Next Oldest | Next Newest »

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)