In my code I use the following structure to avoid conditions in a for loop:
if patch_type == "zeros":
patch_fct = np.zeros
elif patch_type == "ones":
patch_fct = np.ones
elif patch_type == "rand":
patch_fct = np.random.random_sample
else:
raise "Error"
for k in range(10**9):
m, n = comp_size()
bla = patch_fct((m,n))
where patch_fct can be easily used with tupels.
Now I want to use the same approach to create a patch_fct that takes a tupel and returns uniformly distributed random numbers between -1 and 1. How can I do that?
I would like to do something like:
patch_fct = 2. * (np.random.random_sample - 0.5)
The approach from above does not seem to be the right one.
def patch_fct(tup): return 2*(np.random.random_sample(tup) - 0.5)?numpy.random.uniform(low=-1, high=1, size=None)?