bug-apl
[Top][All Lists]

## [Bug-apl] Fwd: tensor product

 From: Jay Foad Subject: [Bug-apl] Fwd: tensor product Date: Wed, 20 May 2015 15:08:18 +0100

```(Forgot to cc the list.)

---------- Forwarded message ----------
Date: 20 May 2015 at 14:55
Subject: Re: [Bug-apl] tensor product

"Why" does it give a multidimensional result? Because that's the way
it's defined in APL. APL has generalised outer product in a way that
works very well with multi-dimensional arrays. The Kronecker product
is a different generalisation, which is useful when you're restricted
to matrices.

Here's a way to get the Kronecker product in APL, using the example
from wikipedia (http://en.wikipedia.org/wiki/Kronecker_product):

kron←{((⍴⍺)+⍴⍵)⍴1 3 2 4⍉⍺∘.×⍵}
⊢a←2 2⍴1 2 3 4
1 2
3 4
⊢b←2 2⍴0 5 6 7
0 5
6 7
a kron b
0  5  0 10
6  7 12 14
0 15  0 20
18 21 24 28

Jay.

On 20 May 2015 at 14:31, Fausto Saporito <address@hidden> wrote:
> Hello all,
>
> I don't understand why the tensor product in APL (∘.×) between two
> matrices, gives a multidimensional array as result.
>
> From linear algebra, tensor product (or kronecker product) gives a
> matrix as result,
>
> for example
>
> if I2 is identity matrix
>
> 1 0
> 0 1
>
> I2 (tensor product) I2 gives
>
> 1 0 0 0
> 0 1 0 0
> 0 0 1 0
> 0 0 0 1
>
> instead if I use the APL operator I have :
>
> 1 0
> 0 1
>
> 0 0
> 0 0
>
>
> 0 0
> 0 0
>
> 1 0
> 0 1
>
> the result is correct but why the shape is different ?
>
> Is there a way to have a behaviour similar to linear algebra result ?
>
> I wrote a generic tensor product function, but I'm not happy because
> it uses loops and I don't like APL with loops :) but I didn't figure
> out a loopless solution.
>
> thanks,
> Fausto
>

```