How to resample an array in python
Question: I am new in python and I have a question about array/matrix. Below is the
matrix I got.

A =

> [[85 77 83 ..., 59 58 59]
>
> [80 83 80 ..., 57 60 58]
>
> [75 76 81 ..., 59 58 60]]

I want to re-sample(I don't know if this is the right word) the matrix so it
becomes

B =

> [[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59
> 59 59]
>
> [ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59
> 59 59]
>
> [ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59
> 59 59]
>
> [ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59
> 59 59]
>
> [ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58
> 58 58]
>
> [ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58
> 58 58]
>
> [ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58
> 58 58]
>
> [ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58
> 58 58]
>
> [ 75 75 75 75 76 76 76 76 81 81 81 81 ....... 59 59 59 59 58 58 58 58 60 60
> 60 60]
>
> [ 75 75 75 75 76 76 76 76 81 81 81 81 ....... 59 59 59 59 58 58 58 58 60 60
> 60 60]
>
> [ 75 75 75 75 76 76 76 76 81 81 81 81 ....... 59 59 59 59 58 58 58 58 60 60
> 60 60]]

I searched online and looked at many posts, but still I have no clue how to do
this. So please teach me how to do this, and I am greatly appreciated.


Answer: Definitely use the info from [Scipy interpolation how to resize/resample 3x3
matrix to 5x5?](http://stackoverflow.com/questions/5586719/scipy-
interpolation-how-to-resize-resample-3x3-matrix-to-5x5) from the comments.

But I thought I'd mess around and here's what I got:

Possibly the worst looking method of all time:

    
    
    >>> import pprint
    >>> a = [[85, 77, 99],
    ...      [11, 22, 33],
    ...      [44, 55, 66]]
    >>> 
    >>> def transform(n,matrix):
    ...     return [item for sublist in [[[item for sublist in [[element]*n for element in row] for item in sublist] for _ in range(n)] for row in matrix] for item in sublist]
    ... 
    >>> pprint.pprint(transform(3,a))
    [[85, 85, 85, 77, 77, 77, 99, 99, 99],
     [85, 85, 85, 77, 77, 77, 99, 99, 99],
     [85, 85, 85, 77, 77, 77, 99, 99, 99],
     [11, 11, 11, 22, 22, 22, 33, 33, 33],
     [11, 11, 11, 22, 22, 22, 33, 33, 33],
     [11, 11, 11, 22, 22, 22, 33, 33, 33],
     [44, 44, 44, 55, 55, 55, 66, 66, 66],
     [44, 44, 44, 55, 55, 55, 66, 66, 66],
     [44, 44, 44, 55, 55, 55, 66, 66, 66]]
    >>> pprint.pprint(transform(4,a))
    [[85, 85, 85, 85, 77, 77, 77, 77, 99, 99, 99, 99],
     [85, 85, 85, 85, 77, 77, 77, 77, 99, 99, 99, 99],
     [85, 85, 85, 85, 77, 77, 77, 77, 99, 99, 99, 99],
     [85, 85, 85, 85, 77, 77, 77, 77, 99, 99, 99, 99],
     [11, 11, 11, 11, 22, 22, 22, 22, 33, 33, 33, 33],
     [11, 11, 11, 11, 22, 22, 22, 22, 33, 33, 33, 33],
     [11, 11, 11, 11, 22, 22, 22, 22, 33, 33, 33, 33],
     [11, 11, 11, 11, 22, 22, 22, 22, 33, 33, 33, 33],
     [44, 44, 44, 44, 55, 55, 55, 55, 66, 66, 66, 66],
     [44, 44, 44, 44, 55, 55, 55, 55, 66, 66, 66, 66],
     [44, 44, 44, 44, 55, 55, 55, 55, 66, 66, 66, 66],
     [44, 44, 44, 44, 55, 55, 55, 55, 66, 66, 66, 66]]
    >>> pprint.pprint(transform(5,a))
    [[85, 85, 85, 85, 85, 77, 77, 77, 77, 77, 99, 99, 99, 99, 99],
     [85, 85, 85, 85, 85, 77, 77, 77, 77, 77, 99, 99, 99, 99, 99],
     [85, 85, 85, 85, 85, 77, 77, 77, 77, 77, 99, 99, 99, 99, 99],
     [85, 85, 85, 85, 85, 77, 77, 77, 77, 77, 99, 99, 99, 99, 99],
     [85, 85, 85, 85, 85, 77, 77, 77, 77, 77, 99, 99, 99, 99, 99],
     [11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33],
     [11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33],
     [11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33],
     [11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33],
     [11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33],
     [44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66],
     [44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66],
     [44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66],
     [44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66],
     [44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66]]
    >>> 
    

