def randslice_from_shape(ndim, shape):
 lslices = ([0] * ndim)
 rslices = ([0] * ndim)
 for n in range(ndim):
  l = shape[n]
  slicelen = (randrange(1, (l + 1)) if (l > 0) else 0)
  lslices[n] = randslice_from_slicelen(slicelen, l)
  rslices[n] = randslice_from_slicelen(slicelen, l)
 return (tuple(lslices), tuple(rslices))

def randslice_from_shape ( ndim , shape ) : lslices = ( [ 0 ] * ndim ) rslices = ( [ 0 ] * ndim ) for n in range ( ndim ) : l = shape [ n ] slicelen = ( randrange ( 1 , ( l + 1 ) ) if ( l > 0 ) else 0 ) lslices [ n ] = randslice_from_slicelen ( slicelen , l ) rslices [ n ] = randslice_from_slicelen ( slicelen , l ) return ( tuple ( lslices ) , tuple ( rslices ) )
create two sets of slices for an array x with shape shape such that shapeof == shapeof .