private static PyMultiarray seqToMultiarray(final PyObject seq, char typecode) {
        final int[] newShape = PyMultiarray.shapeOf(seq);
        final PyObject[] flatData = PyMultiarray.seqToObjects(
                seq,
                PyMultiarray.shapeToNItems(newShape));
        typecode = (typecode == '\0') ? PyMultiarray.objectsToType(flatData)
                : typecode;
        final PyMultiarray newArray = PyMultiarray.zeros(
                PyMultiarray.shapeOf(seq),
                typecode);
        final int size = PyMultiarray.typeToNElements(typecode);
        for (int i = 0; i < flatData.length; i++) {
            Array.set(
                    newArray.data,
                    size * i,
                    PyMultiarray.objectToJava(flatData[i], typecode, true));
        }
        // Set complex elements if array is complex.
        if (size == 2) {
            for (int i = 0; i < flatData.length; i++) {
                Array.set(
                        newArray.data,
                        size * i + 1,
                        PyMultiarray.objectToJava(flatData[i], typecode, false));
            }
        }
        return newArray;
    }