Another numpy array handling question: I have an approx. 2000³ entries numpy array with fixed size (that I know), containing integers. I want to pad the array with another integer, so that it's surrounded in all dimensions. This integer is fixed for the whole padding process.
example (2D)
1----->000
010
000
I have two ideas, leading to that result:
Creating a larger numpy array, containing the padded values and "slicing" the old area in the padded:
padded=np.zeros((z+2,x+2,y+2)) padded[1:z+1,1:x+1,1:y+1]=olddataUsing np.insert or hstack,vstack,dstack to add the values:
padded=np.insert(data,0,0,axis=0) padded=np.insert(data,x+1,0,axis=0) etc.
The Problem is, that all these methods are not in-place and allocate a new array (1.) or copy the old one (2.). Is there a way to do the padding in-place? I know, that since numpy 1.7. there's the numpy.pad module. But that also seems to use some kind of allocation and overriding (like in my 1. way).