Python Forum

Full Version: 20 x 20 Integer array with random numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
I suggest A = 2 * np.random.randint(-1, 1, [20, 20]) + 1
Use np.random.choice. Pass it an array of -1 and 1 and the size.
yeah that works thank you very much