Home > Net >  Scaling a numpy array
Scaling a numpy array

Time:10-30

Is there a way to scale a numpy array so I'd get something like this:

[[ 1  2  3  4]            [[ 1  1  2  2  3  3  4  4]
 [ 5  6  7  8]    ->       [ 1  1  2  2  3  3  4  4]
 [ 9 10 11 12]             [ 5  5  6  6  7  7  8  8]
 [13 14 15 16]]            [ 5  5  6  6  7  7  8  8]
                                      etc...

Basically, in this case the array would be double the shape of the original. When I tried numpy.resize(arr, (arr.shape[0] * 2, arr.shape[1] * 2)), it came out like this:

    [[ 1  2  3  4  5  6  7  8]
     [ 9 10 11 12 13 14 15 16]
     [ 1  2  3  4  5  6  7  8]
     [ 9 10 11 12 13 14 15 16]
     [ 1  2  3  4  5  6  7  8]
     [ 9 10 11 12 13 14 15 16]
     [ 1  2  3  4  5  6  7  8]
     [ 9 10 11 12 13 14 15 16]]               
 

Is there any way to achieve the type of scaling I want on a numpy array directly?

CodePudding user response:

x=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
np.repeat(np.repeat(x, 2,axis=1),2,axis=0)
  • Related