Christian Soeller wrote:
> Maybe that's already implicit in the broadcasting proposal but it
> wouldn't hurt to spell it out:
>
> A dimension size of 1 should be broadcasted to match that of the
> other operand. So, for example, the following shapes (returned by
> @#array) are compatible:
>
> @c = @a * @b
>
> result shape shape @a shape @b
>
> [4,8,5] [4,1,5] [4,8,5]
> [5,3,2] [1,3,2] [5,1,2]
>
Isn't that already spelt out?
<quote>
If the operands are a column vector and a row vector, the elements of each
vector are combined into a two dimensional array:
my int @vec1 = (2,3); # 1st dimension
my int @vec2 = ([2],[3]); # 2nd dimension
@i = @vec1*@vec2; # ([2*2,3*2],[2*3,3*3]) == ([4,6],[6,9])
Equivalent combinatorial broadcasting occurs if the operands are
perpendicular planes (creating a cube), and so forth for higher
dimensional arrays.
</quote>
> In that respect it would be nice to have a slicing syntax to introduce
> 'dummy' dimensions of size 1 (e.g. Yorick uses the concept of a
> pseudo-index, [1]; similarly NumPy [2]; PDL has dummy dimensions via '*'
> using C<slice>):
>
> @a = sin @x; # 1D array
> @b = cos @x;
>
> @twod = @a * @b[-;];
>
> which would be the same as
>
> @twod[|i;|j] = @a[|i] * @b[|j];
>
So is your proposal basically that we need a way to transpose arrays easily?
To be honest, I don't really get the point of stuff like NumPy's "NewAxis",
so I might be misunderstanding your proposal. But at least for your example,
we would just have:
@a = sin @x; # 1D array
@b = cos @x;
@twod = @a * transpose(@b);
or if we don't have a transpose() builtin:
@twod = @a * part(1, @b);