I am trying to create a matrix in a random way in the intervals [-5,-1] and [1,5]. How can I create a matrix taking into account the intervals (no 0 values) with random values?
I tried to do it with randint
of numpy and with piecewise
. In the first case it is not posible to indicate 2 intervals and in the second case the random number generated when the value is close to 0 (bigger than -1 and lower than 1) is always the same.
x=np.random.randint(-5,5,(2,3))
np.piecewise(x, [x <= 1, x >=-1 ], [np.random.randint(-5,-1), np.random.randint(1,5)])
I would like to have a matrix in this way with no 0 values:
[-2,-3,-1
1,-2, 3]