[Tutor] Re: matrix insertion routine for MNA
Abel Daniel
abli at freemail.hu
Thu Oct 21 19:10:54 CEST 2004
CryptoLevel9 at aol.com writes:
[ ...description of problem (how to store multiple elements in a
matrix so they can be summed later) snipped... ]
(Note that I don't actually use numarray, but it should be able to
handle the following suggestions)
Any reason you can't have a 'running sum'? That is, create an empty matrix
(M[i][j]), then for each value to be placed at the (x,y) koordinates
do an:
M[x][y] = M[x][y] + value
If you are only interested in the sum, you might as well be doing the
summing when inserting the elements. In fact, this should be more
efficient as you aren't storing numbers you don't really need.
Another possibility: if you know the maximum number of elements that
should be placed at a given location, (and this number is small) you
could create a matrix which is of one higher dimension. That is,
instead of a matrix of N rows and M columns with each element being an
L lenght list, create one that is NxMxL big. (Which would mean a
three-dimensional matrix.) Of course, it would need to be filled with
zeroes so that the undefined elements won't matter when doing the
summing.
--
Abel Daniel
http://abeld.web.elte.hu
More information about the Tutor
mailing list