How to “scale” a numpy array?

后端 未结 4 2059
天涯浪人
天涯浪人 2020-12-08 07:24

I would like to scale an array of shape (h, w) by a factor of n, resulting in an array of shape (h*n, w*n), with the.

Say that I have a 2x2 array:

ar         


        
4条回答
  •  萌比男神i
    2020-12-08 07:59

    You could use repeat:

    In [6]: a.repeat(2,axis=0).repeat(2,axis=1)
    Out[6]: 
    array([[1, 1, 1, 1],
           [1, 1, 1, 1],
           [0, 0, 1, 1],
           [0, 0, 1, 1]])
    

    I am not sure if there's a neat way to combine the two operations into one.

提交回复
热议问题