2
$\begingroup$

I have this in octave:

octave:139> r
r =

   3   1
   7   2

octave:140> r(2,:)
ans =

   7   2

octave:141> r(1,1)
ans =  3
octave:142> r(1,2)
ans =  1

This kind of indexing indicates to me that the dimension 1 is row and dimension 2 is column.

But down below when I specify dimension 1, I get max along the columns (now rows)

octave:143> max(r,[],1)
ans =

   7   2

And here when I specify dimension 2, I get max along the rows (now colums)

octave:144> max(r,[],2)
ans =

   3
   7

Why so ?

$\endgroup$
3
$\begingroup$

Yeah, that can be a bit confusing. Try to think about it this way:

1 = which row 2 = which column

max(r,[],1) = "get the biggest row" (which of course might be a mixture of different rows).

max(r,[],2) = get the biggest column

Hope this helps to see the reason for this. For matrices it would be possible to use a different convention which might look more intuitve for you. But for higher rank objects (i.e. more than two indices), this convention is the only sensible.

$\endgroup$
0
$\begingroup$

I think a more sensible answer is that the DIM input tells Octave which dimension to take as the independent variable. That is, for example in sum(X, DIM) with DIM =1, at each step the summation is done along the vertical direction (first dimension), which corresponds to the rows as you have observed in your first examples, and the result is a function of the horizontal direction, much like in a double integral.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.