I know there are functions for making arrays of zeros and ones, but I need to make an array of twos.
My ones array works:
np.ones((20), dtype=int).reshape(4, 5)
I just want to replace all the ones with twos in a short line of code.
Try np.full() where you specify fill_value=2:
arr = np.full(20, 2, dtype=int).reshape(4, 5)
print(arr)
Prints:
[[2 2 2 2 2]
[2 2 2 2 2]
[2 2 2 2 2]
[2 2 2 2 2]]
np.zeros