code: public static int[] broadcastOutputShape(int[] left,int[] right) {
          assertBroadcastable(left, right);
          if(Arrays.equals(left,right))
              return left;
          int n = Math.max(left.length,right.length);
          List<Integer> dims = new ArrayList<>();
          int leftIdx = left.length - 1;
          int rightIdx = right.length - 1;
          for(int i = n - 1; i >= 0; i--) {
              if(leftIdx < 0) {
                  dims.add(right[rightIdx]);
              }
              else if(rightIdx < 0) {
                  dims.add(left[leftIdx]);
              }
              else if(left[leftIdx] != right[rightIdx] && right[rightIdx] == 1 || left[leftIdx] == 1) {
                  dims.add(Math.max(left[leftIdx],right[rightIdx]));
              }
              else if(left[leftIdx] == right[rightIdx]) {
                  dims.add(left[leftIdx]);
              }
              else {
                  throw new IllegalArgumentException("Unable to broadcast dimension " + i + " due to shape mismatch. Right shape must be 1.");
              }
  
              leftIdx--;
              rightIdx--;
          }
  
          Collections.reverse(dims);
          return Ints.toArray(dims);
      }
docs: Get the broadcast output shape
  based on the 2 input shapes
  Result output shape based on:
  https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html
  
  
  @param left the left shape
  @param right the right second
  @return