[Jprogramming] Different result of mean for row and column vectors

Hauke Rehr hauke.rehr at uni-jena.de
Wed Apr 15 18:11:42 UTC 2020


In other words, there is no such thing as a “column vector.”
It’s a matrix with “dimension“ 2.
A better way to phrase this is “has 2 axes” or, in J lingo,
as Don Guinn said, it’s about ranks.

You said
rvec =: 1 2 3
rather than
rvec =: 1 3 $ 1 2 3
but with cvec you told j to build a matrix aka rank 2 array

for rvec to be on par with cvec you’ll need
1 3 $ 1 2 3

    mean =: +/ % #
    $ $ mean rvec =: 1 3 $ 1 2 3
1

Am 15.04.20 um 19:37 schrieb Don Guinn:
> The rank is reduced by one. So the rank 2 is reduced to one.
> 
> On Wed, Apr 15, 2020, 11:33 AM Thomas Bulka <thomas.bulka at posteo.de> 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
> 

-- 
----------------------
mail written using NEO
neo-layout.org



More information about the Programming mailing list