文章目錄
- sklearn.utils.shuffle
- astype強制轉換資料型別
- format格式化函式
sklearn.utils.shuffle
- 打亂資料

def shuffle_index(num_samples):
a = range(0, num_samples)
a = shuffle(a)
length = int((num_samples + 1) / 2)
train_index = a[:length]
test_index = a[length:]
return [train_index, test_index]
astype強制轉換資料型別

format格式化函式
- 語法:
str.format()- 用{}和:代替%
- format函式不設定引數:
>>>"{} {}".format("hello", "world") # 不設定指定位置,按默認順序
'hello world'
>>> "{0} {1}".format("hello", "world") # 設定指定位置
'hello world'
>>> "{1} {0} {1}".format("hello", "world") # 設定指定位置
'world hello world'
- 設定引數:
print("用戶名:{name}, 學號 {number}".format(name="universe", number="1207"))
# 通過字典設定引數
site = {"name": "universe", "number": "1207"}
print("用戶名:{name}, 學號 {number}".format(**site))
# 通過串列索引設定引數
my_list = ['universe', '1207']
print("用戶名:{0[0]}, 學號 {0[1]}".format(my_list)) # "0" 是必須的
- 輸出都是:
用戶名:universe, 學號 1207
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/159716.html
標籤:其他
上一篇:OpenCV筆記之五——影像繪制
