[PYTHON MATRIX-SIG] .flat attribute

Jim Hugunin hugunin@mit.edu
Mon, 11 Nov 1996 15:00:11 -0500


>  It seems that the attribute .flat of an array is usable only if the
> array is contiguous.
> (ValueError: flattened indexing only available for contiguous array)
> 
>  This point should be mentionned in the tutorial.

True.  The preferred way to get a flattened array is the ravel function. 
This should always work.

>  Moreover, since a function can't know if the array it will process will
be
> or not contiguous, they are very few cases where .flat is usefull.
> Or did I miss something ?

I start many of my functions with the code:

a = array(a, Float)

This quarantees that I have a contiguous array of C doubles and that I can
modify this array without affecting the arrays held by the caller of the
function.  The obvious problem with this is that it adds an array copy to
every such function.  Where this is a problem I don't do it.


=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================