rougier/numpy-100

Q16 fancy indexing solution does not work

Objectivitix opened this issue · 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.

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.