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

Reply via email to