列出的名單,我想創建一個玩具訓練從XOR功能設置:獲取{} ValueError錯誤「A」必須爲1 - dimensoinal從np.random.choice
xor = [[0, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 0]]
input_x = np.random.choice(a=xor, size=200)
然而,這是給我
{ValueError} 'a' must be 1-dimensoinal
但是,如果我加上eg一個數字到這個清單:
xor = [[0, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 0],
1337] # With this it will work
input_x = np.random.choice(a=xor, size=200)
它開始工作。爲什麼會出現這種情況,如何在不需要向xor
列表中添加另一個基元的情況下如何進行此項工作?
你從'np.random.choice期望(A = XOR,大小= 200 )'單個數字還是具有3個值的數組? – BloodyD
@BloodyD我期望從'xor'中有200個隨機抽取樣本的列表。 – displayname
爲什麼不直接使用'random.choice'呢?因爲你已經在使用Python的列表。 –