From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=2.0 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,32d9aa9d79729b31 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.190.104 with SMTP id gp8mr9678319pbc.4.1340528109843; Sun, 24 Jun 2012 01:55:09 -0700 (PDT) Path: l9ni13838pbj.0!nntp.google.com!news1.google.com!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: Any easy/build-in construct to extract submatrices from larger matrix? Date: Sun, 24 Jun 2012 03:55:08 -0500 Organization: Aioe.org NNTP Server Message-ID: References: Reply-To: nma@12000.org NNTP-Posting-Host: KdJUrTuvv3Zv/s8pPxNluw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-06-24T03:55:08-05:00 List-Id: On 6/24/2012 3:24 AM, Dmitry A. Kazakov wrote: > On Sun, 24 Jun 2012 03:05:37 -0500, Nasser M. Abbasi wrote: > >> fyi, modern Fortran has a nice facility to do this, called >> pack(). It works like this: make up a MASK matrix of same size >> as A. For those elements we want removed, put in a logical >> .false at that location. > > This looks like a low-level hack with unpredictable results, because it > does not specify the dimensions and the order of the elements for the > result matrix. > Pack() returns a vector, not a matrix. That is why reshape() is used. The order is well defined. Fortran uses Fortran order? (column major). So I am not sure I understand your "unpredictable results" ? > If I implemented indicator functions for matrices, with the thingy is, I > would define an abstract type with multiple implementations including a set > of indices. A set would be far more effective for sparse matrices than > Boolean matrix. > Well. Sounds too advanced for me. I was just looking for a little more simple solution. btw, if you think the Fortran solution was short, in Matlab, this is done like this EDU>> A=[1 2 3;4 5 6;7 8 9]; EDU>> A(1,:)=[]; % removes row 1 EDU>> A(:,1)=[] % removes column 1 A = 5 6 8 9 And this would also work if A was sparse in Matlab. regards, --Nasser