def strides_from_shape(ndim, shape, itemsize, layout):
 if (ndim == 0):
  return ()
 if (layout == 'C'):
  strides = (list(shape[1:]) + [itemsize])
  for i in range((ndim - 2), (-1), (-1)):
   strides[i] *= strides[(i + 1)]
 else:
  strides = ([itemsize] + list(shape[:(-1)]))
  for i in range(1, ndim):
   strides[i] *= strides[(i - 1)]
 return strides

def strides_from_shape ( ndim , shape , itemsize , layout ) : if ( ndim == 0 ) : return ( ) if ( layout == 'C' ) : strides = ( list ( shape [ 1 : ] ) + [ itemsize ] ) for i in range ( ( ndim - 2 ) , ( - 1 ) , ( - 1 ) ) : strides [ i ] *= strides [ ( i + 1 ) ] else : strides = ( [ itemsize ] + list ( shape [ : ( - 1 ) ] ) ) for i in range ( 1 , ndim ) : strides [ i ] *= strides [ ( i - 1 ) ] return strides
calculate strides of a contiguous array .