I read one paper and they mentioned as
flipped data with 50% chance along x-axis.
Given an input data is 40x40x24. How can I perform the above requirement? I am trying the bellow code using python 2.7 but I am not sure about "50% chance" meaning
data_flip = np.flipud(data)
data_flip = data[:, ::-1, :]
First, in order to choose out of n
elements with probability p
you can simply use: np.random.rand(n) < p
. r = np.random.rand()
generates a number from a uniform distribution over [0, 1)
, so the probability that r
is smaller than some constant p
(where p
is in [0,1]) is exactly p
. This probability is actually the CDF of the distribution , which in this case where a=0 and b=1 is:
F(p) = 0, p<0
p, 0<=p<=1
1, p>1
Second, to flip the data along the x axis use np.fliplr
rather than np.flipud
(which flips along the y axis):
# generate a 3D array size 3x3x5
A = np.array([[1,2,3],[4,5,6],[7,8,9]])
A = np.tile( np.expand_dims(A, axis=2), (1,1,5) )
# index the 3rd axis with probability 0.5
p = 0.5
idxs = np.random.rand(A.shape[2]) < p
# flip left-right the chosen arrays in the 3rd dimension
A[:,:,idxs] = np.fliplr(A[:,:,idxs])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.