private static int[] fixedShape(int[] shape, final int totalSize) {
        shape = shape.clone();
        int size = 1;
        int rubberAxis = -1;
        for (int i = 0; i < shape.length; i++) {
            if (shape[i] == -1) {
                if (rubberAxis != -1) { throw Py.ValueError("illegal shape"); }
                rubberAxis = i;
            } else {
                size *= shape[i];
            }
        }
        if (rubberAxis != -1) {
            shape[rubberAxis] = totalSize / size;
            size *= shape[rubberAxis];
        }
        if (totalSize != size) { throw Py
                .ValueError("total size of new array must be unchanged"); }
        return shape;
    }