tags: python shuffle Same order list
Usually when doing machine learning problems, you need to prepare training data, usually the sample data and labels are stored in 2 lists, such as train_x = ,train_y = . Sometimes it is necessary to shuffle the data before processing (for example, batch gradient descent algorithm, the data needs to be shuffled). At this time, you need to shuffle the two lists in the same order, so how to achieve it in python? This can be achieved by setting the same random seed and then shuffle. code show as below:
import random
randnum = random.randint(0,100)
random.seed(randnum)
random.shuffle(train_x)
random.seed(randnum)
random.shuffle(train_y)
Article catalog Python - two lists get the same element Python - two lists get the same element Method 1: Turn into a tuple - then A & B Method 2 (While cycle method): Method 3: (FO cycle implemen...
Mainly use list derivatives Give an example Example 2 Example Example...
Sometimes two sets of data, such as features and labels, need to be randomly shuffled together, but you want to record this shuffled order, so what should you do? Here is a good method: Output: If you...
Article catalog Reference URL Judging whether two LISTs have repeated elements Method 1, use traversal Method 2 Judgment different values in two lists Elements in LIST1 in List2 Elements in LIST2 Re...
As a draft, please skip the big man. Listft_targetandft_pre...
Scramble (shuffle) multiple lists using the same sequence Can be used for network training to disrupt the training data tags without changing the correspondence Method one: np.random.shuffle (no retur...
Results of the: Function: permutation returns a random list of the permutation range or returns a new array in a disordered order without changing the original array, If the input is a multi-di...
Topic Merge two row Solution ideas It has begun to be used as two LISTs to modify their values, but it should be modified by the pointer to the list. and there is also a notes that Dummy Node, see Sum...
Leetcode link Iteration time complexity o (n + m) Recursive time complexity o (n + m)...