zero padding a matrix

后端 未结 5 674
深忆病人
深忆病人 2021-01-13 19:18

I have a 16X16 matrix. I have to add it to a 256X256 matrix. Can anyone help me how to make this 16X16 matrix into 256X256 filling the remaining with zeros?

5条回答
  •  伪装坚强ぢ
    2021-01-13 19:36

    First thing to do is create an output matrix that is 256x256, assuming you want to keep the original 256x256 matrix pristine. Next, move the values of the input 256x256 matrix into the output matrix. The next step is to add in the 16x16 elements to the output matrix.

    But, before anyone can really answer this, you need to explain how the 16x16 matrix relates to the 256x256 matrix. In other words, is the first element (0,0) of the 16x16 matrix going to be added to the first element (0,0) of the 256x256 matrix? How about the secound element of (0, 1) - do you know where that is going to be added in? What about element (1, 0) of the 16x16 matrix - what element of the 256x256 matrix does that get added into? Once you figure this out, you should be able to simply code some loops to add in each element of the 16x16 matrix to the appropriate 256x256 output matrix element.

提交回复
热议问题