MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: reading different locations of a matrix specified by indices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113895] Re: reading different locations of a matrix specified by indices
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Wed, 17 Nov 2010 05:30:20 -0500 (EST)
  • References: <ibtl2m$5mf$1@smc.vnet.net>

Am 16.11.2010 11:06, schrieb Nasser M. Abbasi:
> Given a matrix A, and list of locations withing the matrix,
> where each location is given by {i,j} entry, I wanted to
> find the most efficient and clear way to obtain the entries
> in the matrix by these locations.
> 
> I wanted to ask the experts here what they think of this
> method, and if they can suggest a better way.
> 
> Example, given
> 
> A={{1,2,3},
>     {4,5,6},
>     {7,8,9}}
> 
> and wanted to obtain the entries at say {1,1} and {3,3},
> which will be 1 and 9 in this example. So I first made a
> list of the locations :
> 
> pos={ {1,1},{3,3}};
> 
> Then typed
> 
> Map[ A[[Sequence@@ # ]] & , pos ]
> 
> and got back
> 
> {1,9}
> So, this seems to work.
> 
> Any suggestion of may be of a more 'obvious' or better way?

how about this:

Extract[A, pos]

hth,

albert


  • Prev by Date: Does activating 8 disable 7?
  • Next by Date: Re: reading different locations of a matrix specified
  • Previous by thread: Re: reading different locations of a matrix specified by indices
  • Next by thread: reading different locations of a matrix specified by indices list