-
Anonymous
Почему индексация numpy с двоеточием и диапазоном приводит к странному поведению?
Сообщение
Anonymous »
Может ли кто-нибудь объяснить следующее поведение?
Код: Выделить всё
test = np.random.rand(1000, 10)
test.shape
(1000, 10)
idxs = np.random.randint(0, 10, 1000)
idxs.shape
(1000,)
test[:, idxs].shape
(1000, 1000)
test[range(test.shape[0]), idxs].shape
(1000,)
Я ожидаю, что они будут эквивалентны. Что мне не хватает?
Подробнее здесь:
https://stackoverflow.com/questions/683 ... d-behavior
1737147129
Anonymous
Может ли кто-нибудь объяснить следующее поведение?
[code]test = np.random.rand(1000, 10)
test.shape
(1000, 10)
idxs = np.random.randint(0, 10, 1000)
idxs.shape
(1000,)
test[:, idxs].shape
(1000, 1000)
test[range(test.shape[0]), idxs].shape
(1000,)
[/code]
Я ожидаю, что они будут эквивалентны. Что мне не хватает?
Подробнее здесь: [url]https://stackoverflow.com/questions/68388534/why-does-numpy-indexing-with-a-colon-vs-range-result-in-weird-behavior[/url]