Rebin an array to a new shape.
198255
def rebin(a, newshape):
    """"""

    slices = [slice(0, old, float(old)/new)
              for old, new in zip(a.shape, newshape)]
    coordinates = numpy.mgrid[slices]
    # choose the biggest smaller integer index
    indices = coordinates.astype('i')
    return a[tuple(indices)]
20643
function arrayReplaceAt(src, pos, newElements) {
  return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1));
}
1169191
def reshape(self, *shape):
        
        if prod(self.shape) != prod(shape):
            raise ValueError("Reshaping must leave the number of elements unchanged")

        if self.shape[-1] != shape[-1]:
            raise ValueError("Reshaping cannot change the size of the constituent series (last dimension)")

        if self.labels is not None:
            newlabels = self.labels.reshape(*shape[:-1])
        else:
            newlabels = None

        return self._constructor(self.values.reshape(shape), labels=newlabels).__finalize__(self, noprop=('labels',))
85009
function shift(arr) {
    var shifted = splice(arr, 0, 1);
    return {
        array: shifted.array,
        val: arr[0]
    };
}
321828
def _to_array(value):
    """"""
    if hasattr(value, 'shape'):
        return value
    elif hasattr(value, '__len__'):
        return array(value)
    else:
        return float_(value)
1182312
def updateArray(self, array, indices, value):
        
        lin = np.arange(array.size)
        new_array = array.flatten()
        new_array[lin[indices]] = value
        return new_array.reshape(array.shape)
770231
def _transform_to_2d(t):
    """"""
    t = np.asarray(t)

    dim = len(t.shape)
    assert dim <= 2

    if dim < 2:
        t = np.atleast_2d(t).T

    return t
172847
def reshape(self, *dims):
        """"""
        shape = _dims2shape(*dims)
        if _volume(shape) != self.size:
            raise ValueError("expected shape with equal volume")
        return self.__class__(self._items, shape, self.ftype)
987976
def truncate_array(array1, array2, position):
    """"""

    slices = []
    for i in range(array1.ndim):
        xmin = 0
        xmax = array1.shape[i]
        dxlo = array1.shape[i] // 2
        dxhi = array1.shape[i] - dxlo
        if position[i] - dxlo < 0:
            xmin = max(dxlo - position[i], 0)

        if position[i] + dxhi > array2.shape[i]:
            xmax = array1.shape[i] - (position[i] + dxhi - array2.shape[i])
            xmax = max(xmax, 0)
        slices += [slice(xmin, xmax)]

    return array1[slices]
1000199
def transmogrify(l):
  """"""
  d = {l[0]: {}}
  tmp = d
  for c in l:
    tmp[c] = {}
    tmp = tmp[c]
  return d
1018154
function fillCircleArrayRowToMiddle(array, x, y) {
  let i;
  const radius = Math.floor(array.length / 2);
  if (x >= radius) {
    for (i = radius; i < x; i++) {
      array[i][y] = true;
    }
  } else if (x < radius) {
    for (i = x + 1; i < radius; i++) {
      array[i][y] = true;
    }
  }
}
396636
def unblockshaped(arr, h, w):
    
    n, nrows, ncols = arr.shape
    return (arr.reshape(h // nrows, -1, nrows, ncols)
               .swapaxes(1, 2)
               .reshape(h, w))
664933
def transform_from_rot_trans(R, t):
    """"""
    R = R.reshape(3, 3)
    t = t.reshape(3, 1)
    return np.vstack((np.hstack([R, t]), [0, 0, 0, 1]))
556610
def fix_shapes(self):
        
        for i in xrange(self.n_chunks):
            for side in ['left', 'right', 'top', 'bottom']:
                edge = getattr(self, side).ravel()[i]
                if side in ['left', 'right']:
                    shp = [edge.todo.size, 1]
                else:
                    shp = [1, edge.todo.size]
                edge.done = edge.done.reshape(shp)
                edge.data = edge.data.reshape(shp)
                edge.todo = edge.todo.reshape(shp)
1121931
function flatten(array) {
    var result = [], i, n;

    for (i = 0, n = array.length; i < n; i++) {
      if (isArray(array[i])) {
        result = result.concat(flatten(array[i]));
      }
      else {
        result.push(array[i]);
      }
    }

    return result;
  }
1185377
def reshape_z(z, dim_z, ndim):
    

    z = np.atleast_2d(z)
    if z.shape[1] == dim_z:
        z = z.T

    if z.shape != (dim_z, 1):
        raise ValueError('z must be convertible to shape ({}, 1)'.format(dim_z))

    if ndim == 1:
        z = z[:, 0]

    if ndim == 0:
        z = z[0, 0]

    return z
722879
private void resize(int s) {
        int[] n;
        int count;

        n = new int[s];
        count = (s < data.length)? s : data.length;
        System.arraycopy(data, 0, n, 0, count);
        data = n;
    }