Re: Mapping tag-value lists to a third
- To: mathgroup at smc.vnet.net
- Subject: [mg132449] Re: Mapping tag-value lists to a third
- From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
- Date: Wed, 19 Mar 2014 04:23:08 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
Hi,
I have 2 lists of equal length such as
tag={0, 1, 0, 0, 0, 1, 0, 1}; val={f1,f2,f3,f4,f5,f6,f7,f8}
and want to produce a third:
tagval={f2,f6,f8}
with length Count[tag,1] containing the entries of val marked by 1-tags. Should be
something efficient, since the source lists may be large (10^6 to 10^7). Thanks.
Hi, Carlos,
This may be done by several ways. For example, like this:
tag = {0, 1, 0, 0, 0, 1, 0, 1};
val = {f1, f2, f3, f4, f5, f6, f7, f8};
tag.val /. Plus -> List
{f2, f6, f8}
Or like this:
Delete[MapThread[Times, {tag, val}],
Position[MapThread[Times, {tag, val}], 0]]
{f2, f6, f8}
I think one can find also other approaches.
Have fun, Alexei
Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG
Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44
e-mail: alexei.boulbitch at iee.lu