[PYTHON] [Error] TypeError: only integer arrays with one element can be converted to an index

error

I got an error when I tried to randomly retrieve rows from the matrix.

>>> 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

Solution

I solved it by making the matrix np.array

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

Recommended Posts

[Error] TypeError: only integer arrays with one element can be converted to an index
ValueError: only one element tensors can be converted to Python scalars workaround
Only size-1 arrays can be converted to Python scalars
I want to be an OREMO with setParam!
TypeError: can only concatenate str (not "float") to str