'Read the shape of the array described by the header.
The file position after this call is unspecified.'

def shape_from_header(self, hdr):

    mclass = hdr.mclass
    if (mclass == mxFULL_CLASS):
        shape = tuple(map(int, hdr.dims))
    elif (mclass == mxCHAR_CLASS):
        shape = tuple(map(int, hdr.dims))
        if self.chars_as_strings:
            shape = shape[:(-1)]
    elif (mclass == mxSPARSE_CLASS):
        dt = hdr.dtype
        dims = hdr.dims
        if (not ((len(dims) == 2) and (dims[0] >= 1) and (dims[1] >= 1))):
            return ()
        self.mat_stream.seek((dt.itemsize * (dims[0] - 1)), 1)
        rows = np.ndarray(shape=(1,), dtype=dt, buffer=self.mat_stream.read(dt.itemsize))
        self.mat_stream.seek((dt.itemsize * (dims[0] - 1)), 1)
        cols = np.ndarray(shape=(1,), dtype=dt, buffer=self.mat_stream.read(dt.itemsize))
        shape = (int(rows), int(cols))
    else:
        raise TypeError(('No    reader    for    class    code    %s' % mclass))
    if self.squeeze_me:
        shape = tuple([x for x in shape if (x != 1)])
    return shape
