Message Boards Message Boards

0
|
4113 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Calculate the outer product of the third layer's of two lists?

Posted 5 years ago

When there is only one layer in the lists:

    x1 = Range[-1., 1., 0.5];
    y1 = Range[1., -1., -0.5];
    Sqrt@N@Outer[Plus, x1^2, y1^2] // MatrixForm

The result is a {5,5} dimensions list. If the original lists are changed into two {5,5,3} dimensions lists, how to calculate the most inner layer's outer product?

    xx1 = Table[x1, 5];
    yy1 = Table[y1, 5];
    kx={-0.005208333333333333, 0.*10^-18, 0.00520833333333333};
    ky={0.005208333333333333, 0.*10^-18, -0.00520833333333333};
    dx[x_] := x + kx;
    SetAttributes[dx, Listable];
    dy[y_] := y + ky;
    SetAttributes[dy, Listable];
    Sqrt@N@Outer[Plus, dx[xx1]^2, Transpose@dy[yy1]^2, 3] // MatrixForm

The corresponding result should be a {5,5,3,3} dimensions list, but it is a {5, 5, 3, 5, 5, 3} dimensions list.

POSTED BY: Shaohui Yin
2 Replies

Hey Shaohui, how are you?

Do you want to do basically that? enter image description here you could do that

Outer[Plus, dx[xx1][[1, 1]]^2, dy[yy1][[1, 1]]^2, 3]

Result: enter image description here

you will have to run over any i and j in dx and dy.

Is it what you wanted?

Bye.

POSTED BY: Estevao Teixeira
Posted 5 years ago

Hi, Estevao. I have worked it out. Anyway, thank you. Here is my code.

k=3;
kTimes[x_] := Table[x, k]; SetAttributes[kTimes, Listable];
xx2 = kTimes[xx1]; 
yy2 = kTimes[yy1]; 
xx3 = dx[xx22]; 
yy3 =Transpose[dy[yy2], 3 <-> 4];
Sqrt@N@Plus[xx3^2, yy3^2];

In this way, I do not need to use Part, which would be faster.

POSTED BY: Shaohui Yin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract