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


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

Problem with access nested list

Started bySam Takoy <sam.takoy@yahoo.com>
First post2011-08-31 10:08 +0000
Last post2011-08-31 11:42 +0000
Articles 2 — 2 participants

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


Contents

  Problem with access nested list Sam Takoy <sam.takoy@yahoo.com> - 2011-08-31 10:08 +0000
    Re: Problem with access nested list Yves Klett <yves.klett@googlemail.com> - 2011-08-31 11:42 +0000

#4677 — Problem with access nested list

FromSam Takoy <sam.takoy@yahoo.com>
Date2011-08-31 10:08 +0000
SubjectProblem with access nested list
Message-ID<j3l16f$btp$1@smc.vnet.net>
Hi,

Below is a simple code, that constructs the n-dimensional permutation
symbol (http://mathworld.wolfram.com/PermutationSymbol.html). I found
myself jumping through hoops to accomplish a simple task.

The main obstacle was: If I have and n x n x n list "temp", and I want
to access the entry temp[[1, 2, 3]], but the numbers 1 2 and 3 are
available in a list indicies = {1,2,3}, how do I do it? I tried
temp[[list]] but that's not it. What I came up with is essentially

Apply[Part[temp, #]&, indices]

to convert from a list to arguments. I'm sure I'm missing something.

Also, how to avoid the ugly loop?

Many thanks in advance!

Sam

Permutator[n_]  := Module[{temp, perms, i},
   temp = ConstantArray[0, ConstantArray[n, n]];
   setValue[val_][indices__] :=
    Module[{}, Part[temp, indices] = val];

   perms = Permutations[Range[1, n]];
   For[i = 1, i <= Length[perms], i = i + 1,
    setValue[Signature[perms[[i]]]] @@ perms[[i]];
    ];
   temp
   ];

[toc] | [next] | [standalone]


#4684

FromYves Klett <yves.klett@googlemail.com>
Date2011-08-31 11:42 +0000
Message-ID<j3l6nt$d95$1@smc.vnet.net>
In reply to#4677
Have a look at:

m = IdentityMatrix[3];
index = {1, 3};
m[[index]]
m[[Sequence @@ index]]

... so m[[Sequence@@{1,3}]] evaluates to m[[1,3]].

Regards,
Yves

Am 31.08.2011 12:08, schrieb Sam Takoy:
> Hi,
> 
> Below is a simple code, that constructs the n-dimensional permutation
> symbol (http://mathworld.wolfram.com/PermutationSymbol.html). I found
> myself jumping through hoops to accomplish a simple task.
> 
> The main obstacle was: If I have and n x n x n list "temp", and I want
> to access the entry temp[[1, 2, 3]], but the numbers 1 2 and 3 are
> available in a list indicies = {1,2,3}, how do I do it? I tried
> temp[[list]] but that's not it. What I came up with is essentially
> 
> Apply[Part[temp, #]&, indices]
> 
> to convert from a list to arguments. I'm sure I'm missing something.
> 
> Also, how to avoid the ugly loop?
> 
> Many thanks in advance!
> 
> Sam
> 
> Permutator[n_]  := Module[{temp, perms, i},
>    temp = ConstantArray[0, ConstantArray[n, n]];
>    setValue[val_][indices__] :=
>     Module[{}, Part[temp, indices] = val];
> 
>    perms = Permutations[Range[1, n]];
>    For[i = 1, i <= Length[perms], i = i + 1,
>     setValue[Signature[perms[[i]]]] @@ perms[[i]];
>     ];
>    temp
>    ];
> 

[toc] | [prev] | [standalone]


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


csiph-web