arrays

Scott David Daniels Scott.Daniels at Acm.Org
Fri Nov 19 02:44:17 CET 2004


Scott David Daniels wrote:
> If you want to refer to a block of memory that you share with your C
> code (especially if the C code controls the memory, you might also want
> to check out my "Blocks and Views" code at:
> 
>     http://members.dsl-only.net/~daniels/block.html

To follow up on my own post, once you have a View v of, say, 100
floating point data entries:

 >>> multidim = [v[x : x+1] for x in range(0, 100, 10)]
 >>> revdim = [v[x : 100 : 10] for x in range(10)]
 >>> v[27]
     43.6
 >>> multidim[2][7]
     43.6
 >>> revdim[7][2]
     43.6
 >>> multidim[2][7] = 19.1
 >>> multidim[2][7]
     19.1
 >>> revdim[7][2]
     19.1
 >>> v[27]
     19.1

That is, you maintain the mapping to the original memory when taking
strides.  All subscript operations change how the memory is referenced,
not take copies of the memory.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list