Map 1D cell index to a 2D coordinate

    :param i: integer 1D cell index

    :return: (x, y), a 2D coordinate
5686
def relayIndextoCoord(self, i):
    
    x = i % self.relayWidth
    y = i / self.relayWidth
    return x, y
898540
def align(s1, s2, gap=' ', eq=operator.eq):
    '''

    '''
    # first we compute the dynamic programming table
    m, n = len(s1), len(s2)
    table = []  # the table is extended lazily, one row at a time
    row = list(range(n+1))  # the first row is 0, 1, 2, ..., n
    table.append(list(row))  # copy row and insert into table
    for i in range(m):
        p = i
        row[0] = i+1
        for j in range(n):
            t = 0 if eq(s1[i], s2[j]) else 1
            p, row[j+1] = row[j+1], min(p+t, row[j]+1, row[j+1]+1)
        table.append(list(row))  # copy row and insert into table
    # now we trace the best alignment path from cell [m][n] to cell [0],[0]
    s1_, s2_ = '', ''

    i, j = m, n
    while i != 0 and j != 0:
        _, i, j, s1_, s2_ = min(
            (table[i-1][j-1], i-1, j-1, s1[i-1]+s1_, s2[j-1]+s2_),
            (table[i-1][j], i-1, j, s1[i-1]+s1_, gap+s2_),
            (table[i][j-1], i, j-1, gap+s1_, s2[j-1]+s2_)
        )
    if i != 0:
        s1_ = s1[:i]+s1_
        s2_ = gap*i+s2_
    if j != 0:
        s1_ = gap*j+s1_
        s2_ = s2[:j]+s2_
    return s1_, s2_
742126
def remapScipy(im, coords):
    
    height, width = im.shape[0], im.shape[1]
    
    # switch to y,x order
    coords = coords[:,:,::-1]

    # make it (h, w, 3, 3)
    coords_channels = np.empty((height, width, 3, 3))
    coords_channel = np.zeros((height, width, 3))
    coords_channel[:,:,:2] = coords
    coords_channels[:,:,0] = coords_channel
    coords_channels[:,:,1] = coords_channel
    coords_channels[:,:,1,2] = 1
    coords_channels[:,:,2] = coords_channel
    coords_channels[:,:,2,2] = 2
    coords = coords_channels
    
    # (3, h, w, 3)
    coords = np.rollaxis(coords, 3)
        
    return map_coordinates(im, coords, order=1)
765231
def _edge_mapping(G):
    
    edge_mapping = {edge: idx for idx, edge in enumerate(G.edges)}
    edge_mapping.update({(e1, e0): idx for (e0, e1), idx in edge_mapping.items()})
    return edge_mapping
999664
function mesh1D(array, level) {
  var zc = zeroCrossings(array, level)
  var n = zc.length
  var npos = new Array(n)
  var ncel = new Array(n)
  for(var i=0; i<n; ++i) {
    npos[i] = [ zc[i] ]
    ncel[i] = [ i ]
  }
  return {
    positions: npos,
    cells: ncel
  }
}
360357
def coordinates(self, reference=None):
        
        coordinates = [i._coordinates for i in self.get_trace(reference)]
        return functools.reduce(lambda a, b: a + b, coordinates)
1201972
def index_2d(seqs: List[List[Any]], target: Any) -> Tuple[int, int]:
    
    for i in range(len(seqs)):
        for j in range(len(seqs[i])):
            if seqs[i][j] == target:
                return i, j
    raise ValueError('Item not present.')
1135614
def index_to_coords(index, shape):
    ''''''
    coords = []
    for i in xrange(1, len(shape)):
        divisor = int(np.product(shape[i:]))
        value = index // divisor
        coords.append(value)
        index -= value * divisor
    coords.append(index)
    return tuple(coords)
199198
def index_to_loc(self, index):
        
        sz = int(self.shape[0] * self.shape[1])
        idxs = np.array([i for i in range(sz)], dtype=int).reshape(self.shape)
        args = np.argwhere(idxs == index)
        if len(args) < 1:
            raise RuntimeError('Index ({}) is out of range.')
        return args[0]
149379
def _split_indices(self, concat_inds):
        
        clengths = np.append([0], np.cumsum(self.__lengths))
        mapping = np.zeros((clengths[-1], 2), dtype=int)
        for traj_i, (start, end) in enumerate(zip(clengths[:-1], clengths[1:])):
            mapping[start:end, 0] = traj_i
            mapping[start:end, 1] = np.arange(end - start)
        return mapping[concat_inds]
136002
def xistep(self, i):
        
        """

        self.YU[:] = self.Y - self.U[..., i]
        b = np.take(self.ZSf, [i], axis=self.cri.axisK) + \
            self.rho*sl.rfftn(self.YU, None, self.cri.axisN)

        self.Xf[..., i] = sl.solvedbi_sm(np.take(
            self.Zf, [i], axis=self.cri.axisK),
                                         self.rho, b, axis=self.cri.axisM)
        self.X[..., i] = sl.irfftn(self.Xf[..., i], self.cri.Nv,
                                   self.cri.axisN)
1294106
def index_to_coordinate(dims):
    
    _ = divmod  # SO WE KEEP THE IMPORT

    num_dims = len(dims)
    if num_dims == 0:
        return _zero_dim

    prod = [1] * num_dims
    acc = 1
    domain = range(0, num_dims)
    for i in reversed(domain):
        prod[i] = acc
        acc *= dims[i]

    commands = []
    coords = []
    for i in domain:
        if i == num_dims - 1:
            commands.append("\tc" + text_type(i) + " = index")
        else:
            commands.append("\tc" + text_type(i) + ", index = divmod(index, " + text_type(prod[i]) + ")")
        coords.append("c" + text_type(i))
    output = None
    if num_dims == 1:
        code = (
            "def output(index):\n" +
            "\n".join(commands) + "\n" +
            "\treturn " + coords[0] + ","
        )
    else:
        code = (
            "def output(index):\n" +
            "\n".join(commands) + "\n" +
            "\treturn " + ", ".join(coords)
        )

    exec(code)
    return output
1257925
def iu1transform(self, zeta):
        """"""
        x = real(zeta)
        y = imag(zeta)
        z = x*self.radius.real + y*self.radius.imag
        return self.rot_matrix*z + self.center
62544
def get_point_index(point, all_points, eps = 1e-4):
        
        inds = np.where(np.linalg.norm(point - all_points, axis=1) < eps)
        if inds[0].shape[0] == 0:
            return -1
        return inds[0][0]
1355690
def set_i(self, i, data, field, side):
        
        edge = self.get_i(i, side)
        setattr(edge, field, data[edge.slice])
1051771
public static void indexToPointIndex( List<Point2D_I32> sequence , GrowQueue_I32 indexes ,
										  FastQueue<PointIndex_I32> output ) {
		output.reset();

		for( int i = 0; i < indexes.size; i++ ) {
			int index = indexes.data[i];
			Point2D_I32 p = sequence.get(index);

			PointIndex_I32 o = output.grow();
			o.x = p.x;
			o.y = p.y;
			o.index = index;
		}
	}
1013304
def im2mat(I):
    """"""
    return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))