nrjank : i can't use your method because i need to matrix so large...and i'm
afraid to finish memory
how large does yours need to be? It would take exceptionally large amounts of data to hit memory limits for something you showed that can be done in 2D.
example: I had another problem where I was manipulating arrays of 2x2 matrices. I used broadcast projectionof the matrices along 'axes' for time, length, frequency, and eigen space, and then additional artificial axes to avoid loops, simplify calculations, etc. with arbitrary refinement for convergence, especially with poorly chosen initial base, I found out how to quickly exhaust memory on a 32bit system.
(a) Most of us are now working on 64bit systems with much more accessible memory, (b) estimating memory use is fairly simple and can usually be avoided. I was just lazy.