Shuffle functions for ndarrays.¶
Shuffle slices of ndarray along specific axis.¶
-
dlutils.shuffle.
shuffle_ndarray
(x, axis=0)[source]¶ Shuffle slices of ndarray along specific axis.
For example, given a 4-dimentional ndarray, which represents a batch of images in BCHW format, one could shuffle samples in that batch by applying
shuffle_ndarray()
withaxis
= 0.Note
Function does not return anything. It shuffles ndarray inplace.
- Parameters
x (array_like) – ndarray to shuffle.
axis (int, optional) – The axis over which to shuffle. Defaults to 0.
Example
>>> a = np.asarray([[1, 5], [0, 2], [0, 1]]) >>> a array([[1, 5], [0, 2], [0, 1]]) >>> dlutils.shuffle.shuffle_ndarray(a, axis=0) >>> a array([[0, 2], [0, 1], [1, 5]]) >>> dlutils.shuffle.shuffle_ndarray(a, axis=1) >>> a array([[2, 0], [1, 0], [5, 1]])
Shuffle ndarrays in union.¶
-
dlutils.shuffle.
shuffle_ndarrays_in_unison
(arrays, axis=0)[source]¶ Shuffle slices of a list of ndarrays along specific axis with the same permutation for each of the arrays in the list.
Works similar to
shuffle_ndarray()
, but applys the same permutation to all arrays in the listNote
Function does not return anything. It shuffles ndarray inplace. All arrays in the list should have the same shape.