[Numpy-discussion] [NumPy-Tickets] [NumPy] #2067: when x is an N-D array, list(x) produces surprising results

Robert Kern robert.kern@gmail....
Tue Feb 28 09:09:00 CST 2012


Off-Trac comments should probably go to numpy-discussion rather than
back to numpy-tickets. I'm not sure why it's not read-only, but it
should be.

On Tue, Feb 28, 2012 at 01:15, Phillip Feldman
<phillip.m.feldman@gmail.com> wrote:
> I'd appreciate a pointer to something in the NumPy reference material
> that states that a N-dim ndarray is treated as a collection of
> (N-1)-dim ndarrays for purposes of iteration.

I'm not sure anything states that about iteration specifically, but
it's implicit from the documented behavior when given a single integer
index:

  http://docs.scipy.org/doc/numpy/user/basics.indexing.html#single-element-indexing

> Phillip
>
> On Mon, Feb 27, 2012 at 11:45 AM,  <numpy-tickets@scipy.org> wrote:
>> #2067: when x is an N-D array, list(x) produces surprising results
>> ------------------------+---------------------------------------------------
>>  Reporter:  pfeldman    |       Owner:  somebody
>>     Type:  defect      |      Status:  new
>>  Priority:  normal      |   Milestone:  Unscheduled
>> Component:  numpy.core  |     Version:  1.6.1
>>  Keywords:              |
>> ------------------------+---------------------------------------------------
>>
>> Comment(by pv):
>>
>>  The behavior does make sense, and it is what would naturally be expected.
>>  From the point of view of iteration, a N-dim ndarray *is* a collection of
>>  (N-1)-dim sub-arrays. The list constructor merely retains the consistency
>>  between `list(a)[j]` and `list(a[j])`. I don't see any reason to change
>>  this behavior, as raveling is a separate operation.
>>
>> --
>> Ticket URL: <http://projects.scipy.org/numpy/ticket/2067#comment:2>
>> NumPy <http://projects.scipy.org/numpy>
>> My example project
> _______________________________________________
> NumPy-Tickets mailing list
> NumPy-Tickets@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-tickets



-- 
Robert Kern


More information about the NumPy-Discussion mailing list