Here's a trick to speed up np.random.permutation(X.shape) with np.argsort() - np.random.rand(X.shape).argsort() In : np.take(X,np.random.permutation(X.shape),axis=0,out=X) Thus, the implementation would look like this - np.take(X,np.random.permutation(X.shape),axis=0,out=X) Also, np.take facilitates overwriting to the input array X itself with out= option, which would save us memory. You can also use np.random.permutation to generate random permutation of row indices and then index into the rows of X using np.take with axis=0. For example, it is now possible to permute the rows or Treated as a separate 1-D array for every combination of the other Subarrays indexed by an axis are permuted rather than the axis being The new function differs from shuffle and permutation in that the The function is introduced in Numpy's 1.20.0 Release. In : import numpy as npįor other functionalities you can also check out the following functions: The order of sub-arrays is changed but theirĬontents remains the same. This function only shuffles the array along the first axis of a
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |