Zakładając, że obiekt jest naprawdę numpy
tablica ta jest znana jako advanced indexing i wybiera określone kolumny:
>>> import numpy as np
>>> a = np.arange(12).reshape(3,4)
>>> a
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
>>> a[:, [1,2,3]]
array([[ 1, 2, 3],
[ 5, 6, 7],
[ 9, 10, 11]])
>>> a[:, [1,3]]
array([[ 1, 3],
[ 5, 7],
[ 9, 11]])
Zauważ, że to nie będzie działać ze standardowej listy Python:
>>> a.tolist()
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]]
>>> a.tolist()[:,[1,2,3]]
Traceback (most recent call last):
File "<ipython-input-17-7d77de02047a>", line 1, in <module>
a.tolist()[:,[1,2,3]]
TypeError: list indices must be integers, not tuple
Czy jesteś pewien, że 'lista' to lista? Może to być instancja klasy, która nadpisuje '__getitem__' w niecodzienny sposób. – Kevin
Czy próbowałeś pisać (list)? Może to być tablica liczbowa typu numpy lub pandas. – mattexx
@mattexx, nie mam całego kodu, co to robi w numpy i pandach? – Stephan