rougier / numpy-100

100 numpy exercises (with solutions)
MIT License
12.17k stars 5.74k forks source link

Q16 fancy indexing solution does not work #167

Open Objectivitix opened 2 years ago

Objectivitix commented 2 years ago

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.

rougier commented 2 years ago

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.