Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16798

Re: Redudant code for style purposes?

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Redudant code for style purposes?
Date 2014-04-14 09:26 +0000
Message-ID <lig9k1$ce9$1@smc.vnet.net> (permalink)
References <20140413092737.B651E6A38@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


There are often multiple ways to do something with Mathematica. Which is
"better" could be based on code length, execution speed, clarity, first one
arrived at that works (task speed), individual style, individual knowledge
of Mathematica, etc. These can be influenced by the version of Mathematica
being used.


array = RandomReal[{0, 10}, 20];


Table[List @@ array[[i ;; i + 1]], {i, 1, 16}] ==
 Table[List @@ array[[{i, i + 1}]], {i, 16}] ==
 Table[List @@ array[[i ;; i + 1]], {i, 16}] ==
 Table[array[[{i, i + 1}]], {i, 16}] ==
 Table[array[[i ;; i + 1]], {i, 16}] ==
 Partition[array, 2, 1][[1 ;; 16]] ==
 Take[Partition[array, 2, 1], 16] ==
 Partition[Take[array, 17], 2, 1]


True



Bob Hanlon




On Sun, Apr 13, 2014 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?
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar


Thread

Re: Redudant code for style purposes? Bob Hanlon <hanlonr357@gmail.com> - 2014-04-14 09:26 +0000

csiph-web