Improving Numpy Performance

前端 未结 5 1176
暖寄归人
暖寄归人 2020-12-08 11:04

I\'d like to improve the performance of convolution using python, and was hoping for some insight on how to best go about improving performance.

I am currently usin

5条回答
  •  囚心锁ツ
    2020-12-08 11:44

    For the particular example 3x3 kernel, I'd observe that

    1  1  1
    1 -8  1
    1  1  1
    
      1  1  1     0  0  0
    = 1  1  1  +  0 -9  0
      1  1  1     0  0  0
    

    and that the first of these is factorable - it can be convoluted by convolving (1 1 1) for each row, and then again for each column. Then subtract nine times the original data. This may or may not be faster, depending on whether the scipy programmers made it smart enough to automatically do this. (I haven't checked in a while.)

    You probably want to do more interesting convolutions, where factoring may or may not be possible.

提交回复
热议问题