Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #16801
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Redudant code for style purposes? |
| Date | 2014-04-14 09:27 +0000 |
| Message-ID | <lig9la$cet$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
On 4/13/14 at 5:27 AM, andymhancock@gmail.com wrote:
>The Mathematica Cookbook has an example:
>array = RandomReal[{0, 10}, 20] Table[List @@ array[[i ;; i + 1]],
>{i, 1, 16}]
>I'm new to Mathematica, but to me, the "List @@" seems
>redundant. The statements give the same results if I remove
>it. Is there a
>reason for this, either functionally or for clarity?
List@@expr is short for Apply[List,expr] which replaces the head
of expr with List. Since,
In[3]:= Table[Head@array[[i ;; i + 1]], {i, 1, 3}]
Out[3]= {List,List,List}
the syntax is redundant. Also, if I wanted to transform the
original array as is being done, I would use
Partition[array[[;;17]],2,1]
that is
In[4]:= Partition[array[[;; 17]], 2, 1] ==
Table[List @@ array[[i ;; i + 1]], {i, 1, 16}]
Out[4]= True
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar
Re: Redudant code for style purposes? Bill Rowe <readnews@sbcglobal.net> - 2014-04-14 09:27 +0000
csiph-web