I need to compute a second power of a square matrix A (A*A^T), but I am only interested in the values around the diagonal of the result. In other words, I need to compute dot products of neighboring rows, where the neighborhood is defined by some window of fixed size and ideally, I want to avoid computation of the remaining dot products. How to do this in numpy without running the full matrix multiplication with some masking? The resulting array should look as follows:
a1*a1 a1*a2 0 0 0 0
a2*a1 a2*a2 a2*a3 0 0 0
0 a3*a2 a3*a3 a3*a4 0 0
0 0 a4*a3 a4*a4 a4*a5 0...
0 0 0 ...
...
The example matrix contains dot products for neighboring rows. Each row is multiplied only with its left and right neighbour. The zeros should ideally not be computed by the solution in order to save time. This thread seems to be headed in similar direction.