rougier/numpy-100 exercise - Que 16. alternate solution
sudhendra-github opened this issue · 5 comments
sudhendra-github commented
- 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.
rougier commented
Sorry for the delay. You solution is nice. Can you make a PR and add it as "alternative method" ?
acharles7 commented
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" ?
rougier commented
@acharles7 Thanks. Let's first see if @sudhendra-github would like to make a PR
rougier commented
Ok