TypeError: only integer scalar arrays can be converted to a scalar index


TypeError: only integer scalar arrays can be converted to a scalar index

覺得有用的話,歡迎一起討論相互學習~

我的微博我的github我的B站

  • 使用np.random.choice創建list,使用這個List作為Data[] List對象的索引。
  • 出現TypeError: only integer scalar arrays can be converted to a scalar index錯誤。
  • 原始語句:
train_indices = np.random.choice(35444, 24500, replace=False)
writer.writerows(data[train_indices])

TypeError: only integer scalar arrays can be converted to a scalar index錯誤。

解決方案

  • 將List轉換為numpy數組即:np.array(data)[test_indices]
train_indices = np.random.choice(35444, 24500, replace=False)
writer.writerows(np.array(data)[train_indices])


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM