python之路 從列表中隨機取數

2021-08-13 01:03:04 字數 654 閱讀 9308

自學python,這是我發表的第一篇python部落格

列表為[「a」,」j」,」g」,」h」,」k」,」i」,」l」,」f」,」v」,」b」,」2」,」5」,」x」]

import numpy as np

word_list = ["a","j","g","h","k","i","l","f","v","b","2","5","x"]

len_list = range(len(word_list))

#將列表生成字典,key為元列表的id序號,values為對應序號的字母,先使用zip將列表組合,再用dict將列表化為字典,id在前,字元在後

word_dict = dict(zip(word_len,word_list))

result =

random_list = np.random.randint(0,13,5)

random_list.sort()

defrandom_dictvalue

(random_list):

for i in random_list:

return result

random_dictvalue(random_list)

print (result)

從列表中隨機取數

列表為 a j g h k i l f v b 2 5 x 版本1 import numpy as np word list a j g h k i l f v b 2 5 x len list range len word list 將列表生成字典,key為元列表的id序號,values為對應序號...

python 從陣列隨機取資料

在神經網路中,經常會用到批量樣本訓練。我們需要從陣列隨機取資料,主要有以下幾種方法 1 np.random.shuffle 將原陣列打亂 import numpy as np array np.random.randint 1,100,size 10 63 32 80 33 61 45 28 55 ...

mysql列表隨機選資料 從MySQL隨機選取資料

從mysql隨機選取資料 2014 06 23 從mysql隨機選取資料最簡單的辦法就是使用 order by rand 方案一 select from table order by rand limit 0,1 這種方法的問題就是非常慢。原因是因為mysql會建立一張零時表來儲存所有的結果集,然後...