I have huge matrices in the form of
mtx1 = {{24+24 FF[6,9] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[6,9] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[6,9] GG[7,8]+24 FF[7,8] GG[7,8],24+24 FF[5,10] GG[5,10]+24 FF[6,9] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[6,9] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[6,9] GG[7,8]+24 FF[7,8] GG[7,8],24+24 FF[5,10] GG[5,10]+24 FF[6,9] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[6,9] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[6,9] GG[7,8]+24 FF[7,8] GG[7,8]},{24+24 FF[5,10] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[6,9] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[6,9] GG[7,8]+24 FF[7,8] GG[7,8],24+24 FF[5,10] GG[5,10]+24 FF[6,9] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[6,9] GG[7,8]+24 FF[7,8] GG[7,8],24+24 FF[5,10] GG[5,10]+24 FF[6,9] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[6,9] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[7,8] GG[7,8]},{24+24 FF[5,10] GG[5,10]+24 FF[6,9] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[6,9] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[6,9] GG[7,8]+24 FF[7,8] GG[7,8],24+24 FF[5,10] GG[5,10]+24 FF[6,9] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[6,9] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[6,9] GG[7,8]+24 FF[7,8] GG[7,8],24+24 FF[5,10] GG[5,10]+24 FF[6,9] GG[5,10]+24 FF[7,8] GG[5,10]+24 FF[5,10] GG[6,9]+24 FF[6,9] GG[6,9]+24 FF[7,8] GG[6,9]+24 FF[5,10] GG[7,8]+24 FF[6,9] GG[7,8]}};
but the matrices I use are much bigger. Now I want to get rid of each term that contains FF[___]
or GG[___]
. Both always come together, therefore I used
mtx2 = mtx1 /. FF[___] -> 0;
(* mtx2={{24, 24, 24}, {24, 24, 24}, {24, 24, 24}} *)
and got the desired result in mtx2. Unfortunatly it turns out that this zeroing is extremly time-consuming. For my huge matrices, it takes on the order of 100 seconds.
Question:
Is there a more time-efficient way to zero all FF[___]
-terms in mtx1
?
Comparison:
I compare several approaches, for a big 3 big test-matrix. The approaches also include the construction of the matrix.
my original approach
- {174.8417751, 65.4913582, 25.3878123} seconds
Coefficient-Creation of Matrix
- {134.4920621, 51.4260521sec, 19.6079772} seconds
belisarius' Block-evaluation methode
- {82.3675688, 31.5639078, 12.3822025} seconds
eldo's Join/Partition
- {77.8615328, 29.0973367, 11.2742769} seconds
kguler's Block-evaluation
- {75.8906436, 29.1315892, 11.6544345} seconds
Mr.Wizard's mtx1[[All, All, 1]]
- {75.5589726, 29.0378220, 11.9491954} seconds
Edit
The full problem, including the matrix-creation is posted here: Time-efficient creation of matrix
Answer
For the example you gave FF[___]
and GG[___]
are the only non-number terms, therefore by polynomial sort order you could use simply:
mtx1[[All, All, 1]]
{{24, 24, 24}, {24, 24, 24}, {24, 24, 24}}
I shall now look at your newer question where I anticipate a more representative example.
Comments
Post a Comment