private static PyMultiarray arrayToMultiarray(final PyArray seq, final char typecode) {
        Object data = seq.__tojava__(Object.class);
        final char type = PyMultiarray.arrayClassToType(data.getClass());
        final int[] shape = PyMultiarray.arrayDataToShape(data, 0);
        final int[] strides = PyMultiarray.shapeToStrides(
                shape,
                PyMultiarray.typeToNElements(type));
        if (shape.length > 1) {
            final Object flat = Array.newInstance(
                    PyMultiarray.typeToClass(type),
                    PyMultiarray.shapeToNItems(shape));
            PyMultiarray.arrayDataToFlat(data, flat, 0);
            data = flat;
        }
        final PyMultiarray ma = new PyMultiarray(data, type, 0, shape, strides);
        return (typecode == '\0' || typecode == type) ? ma : PyMultiarray
                .array(ma, typecode);
    }