octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #50776] Octave inconsistent with Matlab for co


From: Rik
Subject: [Octave-bug-tracker] [bug #50776] Octave inconsistent with Matlab for corner indexing case
Date: Tue, 11 Apr 2017 19:45:54 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0

Follow-up Comment #3, bug #50776 (project octave):

See this article:
http://blogs.mathworks.com/loren/2006/08/09/essence-of-indexing/

For logical indexing, an array index is always reshaped to a column vector
before indexing.


logical_idx = idx(:);


Thus,


x = reshape (1:9, 3,3)
x =

   1   4   7
   2   5   8
   3   6   9

idx = [true, false;
       true, true];
x(idx)
ans =

   1
   2
   4


This is the generic case of a matrix indexed by a vector so it takes the
index's shape.

In your table, a logical index always produces the shape of the indexed object
for a vector.


// Logical (mask):
//
//   object   | index    | result orientation
//   ---------+----------+-------------------
//   vector   | anything | indexed object


This is really a consequence of the fact that any logical array index is first
converted to a column vector.  And then the general rule is that for
vector/vector operations it is the indexed object whose size is retained.

I still think Octave is actually more correct because the text example is an
array with three dimensions, not a vector, so it should be an example of
matrix/vector indexing.  But, we get to code around their quirks.



    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50776>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]