rougier / numpy-100

100 numpy exercises (with solutions)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rougier/numpy-100 exercise - Que 16. alternate solution

sudhendra-github opened this issue · comments

  1. How to add a border (filled with 0's) around an existing array? (★☆☆)¶

Proposed Solution -

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

Pl. give feedback on this, I am new to Python.

Sorry for the delay. You solution is nice. Can you make a PR and add it as "alternative method" ?

fancier and more readable

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

@rougier Please let me know if you want PR as "alternative method" ?

@acharles7 Thanks. Let's first see if @sudhendra-github would like to make a PR

@rougier Can I start working on this?