LoginSignup
6
3

More than 5 years have passed since last update.

[エラー] TypeError: only integer arrays with one element can be converted to an index

Posted at

エラー

行列からランダムに行を取り出そうとしたらエラーが出た。

>>> x = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5]]
>>> perm = np.random.permutation(6)[:3]
>>> perm
array([0, 2, 4])
>>> x[perm]
TypeError: only integer arrays with one element can be converted to an index

解決

行列をnp.arrayにしたら解決した

>>> x = np.array(x)
>>> x[perm]
array([[0, 0],
       [2, 2],
       [4, 4]])
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3