* to the same shape.
     * @return The merged result.
     */
    public static PyMultiarray choose(final PyObject oA, final PyObject b) {
        PyMultiarray a = PyMultiarray.array(oA);
        final boolean debug_this = false;
        // Convert b into an array of PyMultiarrays.
        // (b must be a PyObject because it might not be rectangular).
        final int n = b.__len__();
        final PyMultiarray[] bs = new PyMultiarray[n];
        for (int i = 0; i < n; i++) {
            bs[i] = PyMultiarray.ascontiguous(b.__getitem__(i));
        }
        // Find a common type for the arrays in bs.
        char type = (n > 0) ? bs[0]._typecode : 'i';
        for (int i = 1; i < n; i++) {
            type = PyMultiarray.commonType(type, bs[i]._typecode);
        }
        // find bs array sizes and coerce its elements to correct type.
        a = PyMultiarray.ascontiguous(a, 'i');
        final int[] sizes = new int[n];
        for (int i = 0; i < n; i++) {
            if (a.dimensions.length < bs[i].dimensions.length) {
                if (debug_this) {
                    System.out.println("choose() got " + a);
                    System.out.println("Comparing with this: " + bs[i]);
                }
                throw Py.ValueError("choice array has too many dimensions: "
                        + bs[i].dimensions.length + " > " + a.dimensions.length);
            }
            for (int j = 0; j < bs[i].dimensions.length; j++) {
                if (a.dimensions[j + a.dimensions.length
                        - bs[i].dimensions.length] != bs[i].dimensions[j]) { throw Py
                        .ValueError("array dimensions must agree."); }
            }
            bs[i] = PyMultiarray.array(bs[i], type);
            sizes[i] = Array.getLength(bs[i].data);
        }
        final PyMultiarray result = PyMultiarray.zeros(a.dimensions, type);
        final PyMultiarray flat = PyMultiarray
                .reshape(result, new int[] { -1 });
        for (int i = 0; i < Array.getLength(flat.data); i++) {
            final int index = Array.getInt(a.data, i);
            if (index < 0 || index >= n) { throw Py
                    .ValueError("invalid entry in choice array"); }
            Array.set(flat.data, i, Array.get(bs[index].data, i % sizes[index]));
        }
        return result;
    }