padding numpy array/matrix with string
Question: I am trying to read a multi-band image in a python code. My requirement is to
form a neighborhood matrix. So I need to pad the matrix with with some number
so as to be able to form neighborhood for each element. Ex. a is a matrix,
padding with 0

    
    
    a= |1 2 3 |
       |4 5 6 |
       |7 8 9 |
    neighborhood matrix = |0 0 0|
                          |0 1 2|
                          |0 4 5|
    

I am using `numpy.pad(below)` for this and it works perfectly with single
band. But for multi-band, it converts noDataValue to its equivalent in 0-255
and pads with it, which I do not want.

    
    
    pixels = np.pad(a, (padding,padding), mode='constant', constant_values=(noDataValue)) 
    

where `padding = 1`, `noDataValue = -999.0` but it automatically converting it
to 125. And this is happening only for multiband. So any help would be
appreciated.

Or

If I can pad matrix with a string, that would be great. I could not find any
function that helps padding with String.

**Update 1** : [enter image description
here](http://i.stack.imgur.com/4uqko.png)


Answer: convert `a` to a type which can be the value noDataValue

e.g.

    
    
    import numpy as np
    # ....
    a = [[1,2,3],[4,5,6],[7,8,9]]
    a = np.array(a).astype(np.float32)
    padding = 2
    noDataValue = -999.0
    pixels = np.pad(a, (padding,padding), mode='constant', constant_values=(noDataValue))
    

It works here

