[Tutor] trying to change the number of elements in array whilepreserving data
Alan Gauld
alan.gauld at btinternet.com
Thu Jun 5 01:22:08 CEST 2008
"Bryan Fodness" <bryan.fodness at gmail.com> wrote
> but I would like to change b to look like this,
>
> [[0 0 0 0 0 0 0 0 0]
> [0 0 3 3 3 3 3 0 0]
> [0 0 3 3 3 3 3 0 0]
> My data will not be regular like these. I have a 400x60 array with
> irregular data that I would like as a 400x400 array.
I'm not quite sure the significance of the last bit but it looks like
you just want to pad equally on both sides with zeros?
N = (400-60)/2 # = 70
padded = [[0]*N + row + [0]*N for row in oldarray]
Untried and maybe not too fast but simple.
Or am I missing a complication?
Alan G.
More information about the Tutor
mailing list