Actually, the dimension lost is the first, as insert [0] (u/) inserts u
between the items [1].

Demonstration:

   $ foo =: i. 2 3 4
2 3 4
   $ +/ foo
3 4

[0]: https://code.jsoftware.com/wiki/Vocabulary/slash
[1]: https://code.jsoftware.com/wiki/Vocabulary/AET#Item

Cheers,

Jan-Pieter

Op wo 15 apr. 2020 om 20:54 schreef Mike Powell <[email protected]>:

> Thomas,
>
> I J there is not really anything for a column vector. If an object, like
> your rvec, has a single dimension it’s a vector. If it has two dimensions,
> as does cvec, it’s a matrix. That’s different from most conventional
> mathematical notation.
>
> When you do the summation with +/ you lose a dimension in the result. So a
> vector sums to a scalar and a matrix (with any number of columns) sums to a
> vector. The dimension lost is the last.
>
> It’s a simple rule that’s consistently applied. So the summation of a rank
> 5 array is a rank 4 array. (Of course, the sum of a scalar is still just a
> scalar.) And the same rule applies if the function is multiply rather than
> add for example.
>
> One of the joys of writing in J (or APL or K) is that very often the code
> you write works for arrays of any rank.
>
> Mike
>
> > On Apr 15, 2020, at 10:33 AM, Thomas Bulka <[email protected]>
> wrote:
> >
> > Hello everyone,
> >
> > I do have some difficulties in understanding a certain behavior. Let's
> assume, I define the classical mean verb, a row vector and a column vector:
> >
> > mean =: +/ % #
> > rvec =: 1 2 3
> > cvec =: 3 1 $ 1 2 3
> >
> > When I apply mean to rvec I get the result 2 (as expected), which
> happens to be a scalar ($$ mean rvec yields 0). When I apply mean to cvec
> the result is a vector ($$ mean cvec yields 1). I'd like to understand, why
> this behavior has been chosen. Do you have any hints for me?
> >
> > Regards,
> >
> > Thomas
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to