Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #16299
| From | Itai Seggev <itais@wolfram.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Creating a list of 1x2 element arrays without |
| Date | 2013-12-02 06:43 +0000 |
| Message-ID | <l7ha7f$pbf$1@smc.vnet.net> (permalink) |
| References | <20131201132345.2493B6A0D@smc.vnet.net> |
| Organization | Time-Warner Telecom |
On Sun, Dec 01, 2013 at 08:23:45AM -0500, 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
You can easily fix up the list structure with Flatten. Note that this is much
more efficient for large datasets than your procedural code, which has
complexity O(n^2) with n the total number of pairs.
In[63]:= Flatten[
Table[{i, j}, {i, 30.0, 45.0, 5.0}, {j, -270.0, -240.0, 10.0}], 1]
Out[63]= {{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.}}
--
Itai Seggev
Mathematica Algorithms R&D
217-398-0700
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Creating a list of 1x2 element arrays without Itai Seggev <itais@wolfram.com> - 2013-12-02 06:43 +0000
csiph-web