private final static PyMultiarray stretchAxes(final PyMultiarray a, final PyMultiarray b) {
        if (a.dimensions.length > b.dimensions.length) {
            final int[] dimensions = a.dimensions.clone();
            final int[] strides = a.strides.clone();
            final int excess = a.dimensions.length - b.dimensions.length;
            for (int i = excess; i < dimensions.length; i++) {
                if (dimensions[i] != b.dimensions[i - excess]) {
                    if (dimensions[i] == 1) {
                        dimensions[i] = b.dimensions[i - excess];
                        strides[i] = 0;
                    }
                    else if (b.dimensions[i - excess] != 1) { throw Py
                            .ValueError("matrices not aligned"); }
                }
            }
            return new PyMultiarray(
                    a.data,
                    a._typecode,
                    a.start,
                    dimensions,
                    strides);
        }
        else {
            final int[] dimensions = b.dimensions.clone();
            final int[] strides = new int[dimensions.length];
            final int excess = b.dimensions.length - a.dimensions.length;
            for (int i = excess; i < dimensions.length; i++) {
                if (dimensions[i] != a.dimensions[i - excess]) {
                    if (dimensions[i] == 1) {
                        dimensions[i] = a.dimensions[i - excess];
                    } else if (a.dimensions[i - excess] == 1) {
                        continue; // Don't set strides.
                    } else {
                        throw Py.ValueError("matrices not aligned");
                    }
                }
                strides[i] = a.strides[i - excess];
            }
            return new PyMultiarray(
                    a.data,
                    a._typecode,
                    a.start,
                    dimensions,
                    strides);
        }
    }