From: Ryan Davis Date: 2012-01-09T12:38:36+09:00 Subject: Re: NArray - from coordinates to index On Jan 8, 2012, at 13:15 , Satsou Sa wrote: > Hi, > > How can we convert a coordinates to an index? > > I'm using the awesome NArray library with some arrays of 1, 2, 3, or > more dimensions. For instance, if we consider this 3x3 array of 2 > dimensions ... > > NArray.int(3,3): > [ [ 0, 0, 0 ], > [ 0, 0, 0 ], > [ 0, 0, 0 ] ] > > ... the square of the coordinate [0,1] have also the index of 3 (and > according to the NArray specs, a[3] is same as a[0,1] if a is 3x3 > array). > > Is there a simple way to find the index, from the coordinates? Use the coordinates as a base N number to convert to a base 10 index: a[0,1] == 10b3 == 1*3^1+0*3^0 == 1*3+0*1 == 3