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


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

Distribute one list element over another

Started byTimm Reinisch <timm.reinisch@sprechkultur.com>
First post2013-04-14 00:36 +0000
Last post2013-04-17 06:30 +0000
Articles 4 — 3 participants

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


Contents

  Distribute one list element over another Timm Reinisch <timm.reinisch@sprechkultur.com> - 2013-04-14 00:36 +0000
    Re: Distribute one list element over another Peter Pein <petsie@dordos.net> - 2013-04-15 06:28 +0000
    Re: Distribute one list element over another Vince Virgilio <blueschi@gmail.com> - 2013-04-16 08:20 +0000
    Re: Distribute one list element over another Timm Reinisch <timm.reinisch@sprechkultur.com> - 2013-04-17 06:30 +0000

#14175 — Distribute one list element over another

FromTimm Reinisch <timm.reinisch@sprechkultur.com>
Date2013-04-14 00:36 +0000
SubjectDistribute one list element over another
Message-ID<kkctn0$7fc$1@smc.vnet.net>
Hallo,

It's difficult to explain what I want to achieve and maybe if I could 
describe it better I  would have been able to google a solution.

My problem deals with lists of lists of the form {a1, a2,  a3, {m1, m2, 
m3, m4}}

e.g.

data =
{
{a1, a2,  a3, {m1, m2, m3, m4}},
{b1, b2,  b3, {n1, n2, n3, n4}},
{c1, c2,  c3, {o1, o2, o3, o4}},
{d1, d2,  d3, {p1, p2, p3, p4}},
}

I want is to go over the list and transform each of the sublists {a1, 
a2,  a3, {m1, m2, m3, m4}} into a list consisting of pairs {{a1, m1},  
{a1, m2}, {a1, m3}, {a1, m4}}
so that for the list given above I get

{
{{a1, m1},  {a1, m2}, {a1, m3}, {a1, m4}},
{{b1, n1},  {b1, n2}, {b1, n3}, {b1, n4}},
{{c1, o1},  {c1, o2}, {c1, o3}, {c1, o4}},
{{d1, p1},  {d1, p2}, {d1, p3}, {d1, p4}},
}

I think it could be possible to do this using two nested map operations 
/@, but I don't find out how to do so exactly, because I run into 
trouble with the scope of the #

What I'm doing at the moment is that I use a module:

verteilen[liste_] := Module[{},
  {#[[1]], liste[[1]]} & /@ liste[[4]]
]

and map it over the list I want to transform:

verteilen[#] & /@ data

I'm searching for a much mor elegant way to achive this transformation, 
any hints?

Thanks and best regards

 Timm

[toc] | [next] | [standalone]


#14185

FromPeter Pein <petsie@dordos.net>
Date2013-04-15 06:28 +0000
Message-ID<kkg6lj$j8u$1@smc.vnet.net>
In reply to#14175
Am 14.04.2013 02:36, schrieb Timm Reinisch:
> Hallo,
> 
> It's difficult to explain what I want to achieve and maybe if I could 
> describe it better I  would have been able to google a solution.
> 
> My problem deals with lists of lists of the form {a1, a2,  a3, {m1, m2, 
> m3, m4}}
> 
> e.g.
> 
> data =
> {
> {a1, a2,  a3, {m1, m2, m3, m4}},
> {b1, b2,  b3, {n1, n2, n3, n4}},
> {c1, c2,  c3, {o1, o2, o3, o4}},
> {d1, d2,  d3, {p1, p2, p3, p4}},
> }
> 
> I want is to go over the list and transform each of the sublists {a1, 
> a2,  a3, {m1, m2, m3, m4}} into a list consisting of pairs {{a1, m1},  
> {a1, m2}, {a1, m3}, {a1, m4}}
> so that for the list given above I get
> 
> {
> {{a1, m1},  {a1, m2}, {a1, m3}, {a1, m4}},
> {{b1, n1},  {b1, n2}, {b1, n3}, {b1, n4}},
> {{c1, o1},  {c1, o2}, {c1, o3}, {c1, o4}},
> {{d1, p1},  {d1, p2}, {d1, p3}, {d1, p4}},
> }
> 
> I think it could be possible to do this using two nested map operations 
> /@, but I don't find out how to do so exactly, because I run into 
> trouble with the scope of the #
> 
> What I'm doing at the moment is that I use a module:
> 
> verteilen[liste_] := Module[{},
>   {#[[1]], liste[[1]]} & /@ liste[[4]]
> ]
> 
> and map it over the list I want to transform:
> 
> verteilen[#] & /@ data
> 
> I'm searching for a much mor elegant way to achive this transformation, 
> any hints?
> 
> Thanks and best regards
> 
>  Timm
> 
> 

Hi Timm,

 how about Thread[#[[{1, -1}]]] & /@ data ?

Peter

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


#14200

FromVince Virgilio <blueschi@gmail.com>
Date2013-04-16 08:20 +0000
Message-ID<kkj1l8$1g$1@smc.vnet.net>
In reply to#14175
Thread /@ data[[All,{1,-1}]]

Vince


On Saturday, April 13, 2013 8:36:48 PM UTC-4, Timm Reinisch wrote:
> Hallo,
> 
> 
> 
> It's difficult to explain what I want to achieve and maybe if I could 
> 
> describe it better I  would have been able to google a solution.
> 
> 
> 
> My problem deals with lists of lists of the form {a1, a2,  a3, {m1, m2, 
> 
> m3, m4}}
> 
> 
> 
> e.g.
> 
> 
> 
> data =
> 
> {
> 
> {a1, a2,  a3, {m1, m2, m3, m4}},
> 
> {b1, b2,  b3, {n1, n2, n3, n4}},
> 
> {c1, c2,  c3, {o1, o2, o3, o4}},
> 
> {d1, d2,  d3, {p1, p2, p3, p4}},
> 
> }
> 
> 
> 
> I want is to go over the list and transform each of the sublists {a1, 
> 
> a2,  a3, {m1, m2, m3, m4}} into a list consisting of pairs {{a1, m1},  
> 
> {a1, m2}, {a1, m3}, {a1, m4}}
> 
> so that for the list given above I get
> 
> 
> 
> {
> 
> {{a1, m1},  {a1, m2}, {a1, m3}, {a1, m4}},
> 
> {{b1, n1},  {b1, n2}, {b1, n3}, {b1, n4}},
> 
> {{c1, o1},  {c1, o2}, {c1, o3}, {c1, o4}},
> 
> {{d1, p1},  {d1, p2}, {d1, p3}, {d1, p4}},
> 
> }
> 
> 
> 
> I think it could be possible to do this using two nested map operations 
> 
> /@, but I don't find out how to do so exactly, because I run into 
> 
> trouble with the scope of the #
> 
> 
> 
> What I'm doing at the moment is that I use a module:
> 
> 
> 
> verteilen[liste_] := Module[{},
> 
>   {#[[1]], liste[[1]]} & /@ liste[[4]]
> 
> ]
> 
> 
> 
> and map it over the list I want to transform:
> 
> 
> 
> verteilen[#] & /@ data
> 
> 
> 
> I'm searching for a much mor elegant way to achive this transformation, 
> 
> any hints?
> 
> 
> 
> Thanks and best regards
> 
> 
> 
>  Timm

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


#14212

FromTimm Reinisch <timm.reinisch@sprechkultur.com>
Date2013-04-17 06:30 +0000
Message-ID<kklfi9$7pq$1@smc.vnet.net>
In reply to#14175
Hallo,

Thank you to all of you for your helpful answers!

best regards
 Timm

[toc] | [prev] | [standalone]


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


csiph-web