程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Programming learning: random Introduction to shuffle and detailed introduction to how to use it

編輯:Python

Python Programming learning :random.shuffle An introduction to the 、 A detailed introduction to how to use

Catalog

random.shuffle An introduction to the

random.shuffle How to use

1、 Disarrange two lists and follow the same rule


random.shuffle An introduction to the

       random.shuffle Method , Reorder elements , Upset the original order , Returns a random sequence ( Of course, the random sequence here belongs to pseudorandom , Can be reproduced ), This method is similar to shuffling .

random.shuffle How to use

1、 Disarrange two lists and follow the same rule

import random
X_lists = [[1,2,3,4,5],
[11,12,13,14,15],
[21,22,23,24,25],
[31,32,33,34,35],
[41,42,43,44,45]]
y_lists = [0,10,20,30,40]
print("before:",X_lists,'\n',y_lists)
# # T1、 utilize random Function implementation
# random.seed(123)
# random.shuffle(X_lists) #shuffle Method
# random.seed(123) # For similar data , Random execution of the same rule , This line must be added
# random.shuffle(y_lists)
# print("after:",X_lists,'\n',y_lists)
# T2、 utilize np.random Function implementation
import numpy as np
np.random.seed(123)
np.random.shuffle(X_lists)
np.random.seed(123) # For similar data , Random execution of the same rule , This line must be added
np.random.shuffle(y_lists)
print("after:",X_lists,'\n',y_lists)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved