[Numpy-discussion] Counting array elements
verveer at embl-heidelberg.de
Mon Oct 25 09:47:01 CDT 2004
On 25 Oct 2004, at 18:34, Stephen Walton wrote:
> On Mon, 2004-10-25 at 09:19 -0700, Stephen Walton wrote:
>> On Mon, 2004-10-25 at 10:26 +0200, Peter Verveer wrote:
>>> I think this may be inefficient, because ravel and flat may make a
>>> of the data. Also I think using flat/ravel in such a way is plain
>>> and a complex way to do it.
>> You may be right about the copying, I couldn't say.
> I just looked at the source (numeric-1.1/Lib/generic.py). The comment
> to the ravel() function states that it returns a view, not a copy; but
> it calls reshape() which does make a copy if the input array is not
> contiguous. I just tested this:
> A.transpose() # now A is not contiguous
> v # verifies that v did not change.
> So, in the above, it does look like ravel() made a copy, and your fears
> about inefficiency are warranted. Another test shows that changing
> ravel(A) to A.flat above also results in a copy. Mayhaps we need
> sumall() after all.
Yes, we do I guess, but I do not like such things creeping into an
otherwise elegant package if I may be frank...
More information about the Numpy-discussion