[Numpy-discussion] should a flatiter object get a 'dtype' attribute ?

Travis Oliphant oliphant at ee.byu.edu
Thu Aug 24 14:07:44 CDT 2006


Sebastian Haase wrote:

>Hi,
>I suppose the answer is no .
>But converting more code to numpy I got this error
>AttributeError: 'numpy.flatiter' object has no attribute 'dtype'
>(I found that I did not need the .flat in the first place )
>So I was just wondering if (or how much) a  flatiter object should behave like
>an ndarray ?
>  
>
It's a good question.  Right now, they act like an array when passed to 
functions, but don't have the same attributes and/or methods of an 
ndarray.   I've not wanted to add them because I'm not sure how far 
thinking that a.flat is an actual array will go and so it's probably 
better not to try and hide the fact that it isn't an array object.

I've slowly added a few things (like comparison operators), but the 
real-purpose of the object returned from .flat is for indexing using 
flat indexes into the array.

a.flat[10] = 10

a.flat[30]

Beyond that you should use .ravel() (only copies when necessary to 
create a contiguous chunk of data) and .flatten() (copies all the time).

-Travis





More information about the Numpy-discussion mailing list