Kronecker product with arrays

Hi,

I want to know if there is a way to compute kronecker product with arrays since the usual operator .*.  is not defined for arrays.

My problem is that of repeating values of an array across a certain dimension:

a[1,.,.]=1 |2|3; to b[1,.,.]=1 1 | 2 2 | 3 3;

and the same for every dimension of a (a[2,.,.], a[3,.,.] and so on)

Kronecker product seems to be a way to get this since:

b[1,.,.]=a[1,.,.].*.{1 1};

The command areshape seems to be working on similar lines, but it takes all the values of the original array at once and starts repeating in the same order (as if it vectorized it to then assign its values to a new array of the specified dimensions).

I'm sorry for how confusing my question is, I hope you can help me.

 

Sergio

1 Answer



0



OK, if we want to create a that equals:

plane [1,.,.]

1 1 1
2 2 2
3 3 3

plane [2,.,.]

1 1 1
2 2 2
3 3 3

Then I would do this:

r = 3;
c = 3;
m = 2;

val = { 1, 2, 3 };
a = ones(r, c) .* val;

a = areshape(a, m|r|c);

or if I wanted to be more compact, I might do this:

a = areshape(ones(3,3) .* seqa(1,1,3), 2|3|3)

aptech

1,773

Your Answer

1 Answer

0

OK, if we want to create a that equals:

plane [1,.,.]

1 1 1
2 2 2
3 3 3

plane [2,.,.]

1 1 1
2 2 2
3 3 3

Then I would do this:

r = 3;
c = 3;
m = 2;

val = { 1, 2, 3 };
a = ones(r, c) .* val;

a = areshape(a, m|r|c);

or if I wanted to be more compact, I might do this:

a = areshape(ones(3,3) .* seqa(1,1,3), 2|3|3)

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.