numpy-100 icon indicating copy to clipboard operation
numpy-100 copied to clipboard

Q16 fancy indexing solution does not work

Open Objectivitix opened this issue 2 years ago • 1 comments

An example:

>>> a = np.random.randint(0, 10, (3, 3))
>>> a[:, [0, -1]] = 0
>>> a[[0, -1], :] = 0
>>> a
array([[0, 0, 0],
       [0, 5, 0],
       [0, 0, 0]])

Unless I'm understanding the question incorrectly here (but the np.pad solution is doing what I first expected), the fancy indexing solution does not work.

Objectivitix avatar Jan 04 '22 19:01 Objectivitix

The first solution extends the array (final shape is (5,5)) while the second solution does not. Maybe it's worth to add a comment saying external/internal border to distinguish between the two solutions.

rougier avatar Jan 05 '22 08:01 rougier