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


Groups > comp.soft-sys.math.mathematica > #16294 > unrolled thread

Creating a list of 1x2 element arrays without procedural programming

Started byamannucci <Anthony.J.Mannucci@jpl.nasa.gov>
First post2013-12-01 13:13 +0000
Last post2013-12-02 06:51 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Creating a list of 1x2 element arrays without procedural programming amannucci <Anthony.J.Mannucci@jpl.nasa.gov> - 2013-12-01 13:13 +0000
    Re: Creating a list of 1x2 element arrays without procedural programming Roland Franzius <roland.franzius@uos.de> - 2013-12-02 06:46 +0000
    Re: Creating a list of 1x2 element arrays without procedural programming "Nasser M. Abbasi" <nma@12000.org> - 2013-12-02 06:46 +0000
    Re: Creating a list of 1x2 element arrays without procedural programming "Dr. Wolfgang Hintze" <weh@snafu.de> - 2013-12-02 06:51 +0000

#16294 — Creating a list of 1x2 element arrays without procedural programming

Fromamannucci <Anthony.J.Mannucci@jpl.nasa.gov>
Date2013-12-01 13:13 +0000
SubjectCreating a list of 1x2 element arrays without procedural programming
Message-ID<l7fckt$k44$1@smc.vnet.net>
Is there a way in Mathematica using built-in functions to create what the following procedural program does?

latlong = {}
Do[AppendTo[latlong, {i, j}] , {i, 30.0, 45.0, 
   5.0}, {j, -270.0, -240.0, 10.0}];
latlong

Out:
{{30., -270.}, {30., -260.}, {30., -250.}, {30., -240.}, {35., \
-270.}, {35., -260.}, {35., -250.}, {35., -240.}, {40., -270.}, {40., \
-260.}, {40., -250.}, {40., -240.}, {45., -270.}, {45., -260.}, {45., \
-250.}, {45., -240.}}

Thanks!

-Tony

[toc] | [next] | [standalone]


#16303

FromRoland Franzius <roland.franzius@uos.de>
Date2013-12-02 06:46 +0000
Message-ID<l7haba$pbt$1@smc.vnet.net>
In reply to#16294
Am 01.12.2013 14:13, schrieb amannucci:
> Is there a way in Mathematica using built-in functions to create what the following procedural program does?
>
> latlong = {}
> Do[AppendTo[latlong, {i, j}] , {i, 30.0, 45.0,
>     5.0}, {j, -270.0, -240.0, 10.0}];
> latlong
>
> Out:
> {{30., -270.}, {30., -260.}, {30., -250.}, {30., -240.}, {35., \
> -270.}, {35., -260.}, {35., -250.}, {35., -240.}, {40., -270.}, {40., \
> -260.}, {40., -250.}, {40., -240.}, {45., -270.}, {45., -260.}, {45., \
> -250.}, {45., -240.}}

Some more constructs

latlong = {};
Do[AppendTo[latlong, {i, j}], {i, 30.0, 45.0,
    5.0}, {j, -270.0, -240.0, 10.0}];

table = Flatten[
    Table[{i, j}, {i, 30.0, 45.0, 5.0}, {j, -270.0, -240.0, 10.0}], 1];

array = Flatten[Array[{25.0 + 5 #1, -280.0 + 10 #2} &, {4, 4}], 1];

outer = Flatten[
    Outer[List, Range[30.0, 45.0, 5.0], Range[-270.0, -240.0, 10.0]],
    1];

functions1 =
   Flatten[Function[ x, {x, #1} & /@ Range[-270.0, -240.0, 10.0]] /@
     Range[30.0, 45.0, 5], 1];

vectors = ({25.0, -280.0} + # &) /@
    Flatten[Outer[List, ##] & @@ ((Range[1, 4]*# &) /@ {5, 10}), 1];

flc = Flatten[
    Outer[List, ##] & @@ (({5 #, 10 #} &)[
        Range[1, 4]] + {25.0, -280.0}), 1];


latlong == table == array == outer == functions == vectors == flc


True

-- 

Roland Franzius

[toc] | [prev] | [next] | [standalone]


#16304

From"Nasser M. Abbasi" <nma@12000.org>
Date2013-12-02 06:46 +0000
Message-ID<l7habu$pc0$1@smc.vnet.net>
In reply to#16294
On 12/1/2013 7:13 AM, amannucci wrote:
> Is there a way in Mathematica using built-in functions to create what the following
>procedural program does?
>
> latlong = {}
> Do[AppendTo[latlong, {i, j}] , {i, 30.0, 45.0,
>     5.0}, {j, -270.0, -240.0, 10.0}];
> latlong
>
> Out:
> {{30., -270.}, {30., -260.}, {30., -250.}, {30., -240.}, {35., \
> -270.}, {35., -260.}, {35., -250.}, {35., -240.}, {40., -270.}, {40., \
> -260.}, {40., -250.}, {40., -240.}, {45., -270.}, {45., -260.}, {45., \
> -250.}, {45., -240.}}
>
> Thanks!
>
> -Tony
>

many ways. One way

lst1 = Range[30.0, 45.0, 5.0];
lst2 = Range[-270.0, -240.0, 10.0];
Flatten[Map[ Thread[{#, lst2}] &, lst1], 1];

--Nasser

[toc] | [prev] | [next] | [standalone]


#16308

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2013-12-02 06:51 +0000
Message-ID<l7hal8$pcn$1@smc.vnet.net>
In reply to#16294
Am Sonntag, 1. Dezember 2013 14:13:01 UTC+1 schrieb amannucci:
> Is there a way in Mathematica using built-in functions to create what the following procedural program does?
> 
> 
> 
> latlong = {}
> 
> Do[AppendTo[latlong, {i, j}] , {i, 30.0, 45.0, 
> 
>    5.0}, {j, -270.0, -240.0, 10.0}];
> 
> latlong
> 
> 
> 
> Out:
> 
> {{30., -270.}, {30., -260.}, {30., -250.}, {30., -240.}, {35., \
> 
> -270.}, {35., -260.}, {35., -250.}, {35., -240.}, {40., -270.}, {40., \
> 
> -260.}, {40., -250.}, {40., -240.}, {45., -270.}, {45., -260.}, {45., \
> 
> -250.}, {45., -240.}}
> 
> 
> 
> Thanks!
> 
> 
> 
> -Tony

In[23]:= Flatten[
 Table[{30 + 5*i, -270 + 10*j}, {i, 0, 3}, {j, 0, 3}], 1]

Out[23]= {{30, -270}, {30, -260}, {30, -250}, {30, -240}, {35, -270}, \
{35, -260}, {35, -250}, {35, -240}, {40, -270}, {40, -260}, {40, \
-250}, {40, -240}, {45, -270}, {45, -260}, {45, -250}, {45, -240}}

Regards,
Wolfgang

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web