MathGroup Archive 2012

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

Search the Archive

Re: take square of the second and third column of a table


On 1/11/2012 4:21 PM, hanciong awesome wrote:

>
> how can I take square of the 2nd and 3rd column?

I forgot to mention the simplest method, which is to square the slice
of the matrix directly.


tbl = {{1, 2, 3},{4, 5, 6},{7, 8, 9},{2, 3, 4}}

for second col:

tbl[[All, 2]]^2
-->{4, 25, 64, 9}

to do both cols at same time:

tbl[[All, {2, 3}]]^2
---> {{4, 9}, {25, 36}, {64, 81}, {9, 16}}

I like to Map allot, and so sometimes I overlook that it might not
be needed.

--Nasser







  • Prev by Date: import issue
  • Next by Date: Re: take square of the second and third column of a table
  • Previous by thread: Re: take square of the second and third column of a table
  • Next by thread: Re: take square of the second and third column of a table