1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| from numarray import *
def border2(tab, nbrows, nbcols):
rc, cc = tab.shape
if (nbrows-rc) % 2 == 1: raise Exception, 'impossible de centrer le tableau'
else: b1 = array(((nbrows-rc) / 2) * [cc*[0]])
print b1
if (nbcols-cc) % 2 == 1 : raise Exception, 'impossible de centrer le tableau'
b2 = array(((nbcols-cc)/2) * [nbrows*[0]])
b2.transpose()
print b2
tab = concatenate((tab, b1), 0)
tab = concatenate((b1,tab), 0)
tab = concatenate((tab, b2), 1)
tab = concatenate((b2, tab), 1)
return tab
tab = array([[1,1,1,1],[1,1,1,1],[1,1,1,1]])
print border2(tab, 7, 10) |
Partager