Here you can find the source of maxIndex(int[] shape)
public static int maxIndex(int[] shape)
//package com.java2s; /* --------------------------------------------------------------------- * Numenta Platform for Intelligent Computing (NuPIC) * Copyright (C) 2014, Numenta, Inc. Unless you have an agreement * with Numenta, Inc., for a separate license for this software code, the * following terms and conditions apply: * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero Public License for more details. * * You should have received a copy of the GNU Affero Public License * along with this program. If not, see http://www.gnu.org/licenses. * * http://numenta.org/licenses///from w ww. j a v a 2s.c o m * --------------------------------------------------------------------- */ public class Main { public static int maxIndex(int[] shape) { return shape[0] * Math.max(1, initDimensionMultiples(shape)[0]) - 1; } /** * Returns the maximum value in the specified array * @param array * @return */ public static int max(int[] array) { int max = Integer.MIN_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] > max) { max = array[i]; } } return max; } /** * Returns the maximum value in the specified array * @param array * @return */ public static double max(double[] array) { double max = Double.MIN_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] > max) { max = array[i]; } } return max; } /** * Initializes internal helper array which is used for multidimensional * index computation. * * @param shape an array specifying sizes of each dimension * @return */ public static int[] initDimensionMultiples(int[] shape) { int holder = 1; int len = shape.length; int[] dimensionMultiples = new int[shape.length]; for (int i = 0; i < len; i++) { holder *= (i == 0 ? 1 : shape[len - i]); dimensionMultiples[len - 1 - i] = holder; } return dimensionMultiples; } }