Re: Problem: a matrix and a box...
- To: mathgroup at smc.vnet.net
- Subject: [mg27266] Re: [mg27268] Problem: a matrix and a box...
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Sun, 18 Feb 2001 02:52:05 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
To write such a program in Mathematica is a breeze but there seems to be a snag... First we define our function: func[l_List] /; (Length[l] == 2) := {Plus @@@ Plus @@@ Transpose[Partition[#, 2, 1] & /@ l]}; func[l_List] /; (Length[l] > 2) := Flatten[func /@ Partition[l, 2, 1], 1] Next, we check that it works: (m = {{a1, a2, a3, a4, a5}, {b1, b2, b3, b4, b5}, {c1, c2, c3, c4, c5}, {e1, e2, e3, e4, e5}, {h1, h2, h3, h4, h5}}); func[m] {{a1 + a2 + b1 + b2, a2 + a3 + b2 + b3, a3 + a4 + b3 + b4, a4 + a5 + b4 + b5}, {b1 + b2 + c1 + c2, b2 + b3 + c2 + c3, b3 + b4 + c3 + c4, b4 + b5 + c4 + c5}, {c1 + c2 + e1 + e2, c2 + c3 + e2 + e3, c3 + c4 + e3 + e4, c4 + c5 + e4 + e5}, {e1 + e2 + h1 + h2, e2 + e3 + h2 + h3, e3 + e4 + h3 + h4, e4 + e5 + h4 + h5}} Now the snag. We look at some timings for matrices of the size of the order you are interested in: T = Array[Random[] &, {500, 500}]; func[T]; // Timing {32.2833 Second, Null} Not too bad. Next, we double both dimensions: T = Array[Random[] &, {1000, 1000}]; func[T]; // Timing {388.433 Second, Null} Quite a big jump. Now T = Array[Random[] &, {3000, 3000}]; func[T]; // Timing Mathematica 4.1 for Macintohs runs out of memory immediately (the Kernel had 350 megabytes). So unless someone can come up with a code that is much more memory efficient it looks like you may be out of luck. -- Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ on 01.2.17 5:30 PM, Bedrosian Baol at Bedrosian at MailAndNews.com wrote: > Hi > this is the problem: I have a n x m matrix (with n and m ~3000 elements or > more) > > a1 a2 a3.. > b1 b2 b3.. > c1 c2 c3.. > . . . > . . . > > the algorythm is: compute the summ of the the a1, a2, b1 and b2 elements (a > ''gliding box'' 2x2), shifing the ''box'' for 1 column and repeat the sum of > the elements (now a2, a3, b2, b3), and so on... > at the and of the first line, the box return on the second line and > repeat... > > the final resuls would be another matrix like this: > > [a1+a2+b1+b2] [a2+a3+b2+b3]... > [b1+b2+c1+c2] [b2+b3+c2+c3]... > ... > > I'm not very experienced with Math4: there is a simple and easy way for > reach > the result? > > thanks > Bed > > >