The number of vectors
in each slice of an ndarray.
@param arr the array to
get the number
of vectors per slice for
@param rank the dimensions to get the number of vectors per slice for
@return the number of vectors per slice
420648
public static long vectorsPerSlice(INDArray arr, int... rank) {
        if (arr.rank() > 2) {
            return arr.size(-2) * arr.size(-1);
        }

        return arr.size(-1);

    }
1128967
public static Vector toVector(INDArray arr) {
        if (!arr.isVector()) {
            throw new IllegalArgumentException("passed in array must be a vector");
        }
        // FIXME: int cast
        double[] ret = new double[(int) arr.length()];
        for (int i = 0; i < arr.length(); i++) {
            ret[i] = arr.getDouble(i);
        }

        return Vectors.dense(ret);
    }
771897
public RowVector getRow(int r) throws MatrixException
    {
        if ((r < 0) || (r >= nRows)) {
            throw new MatrixException(MatrixException.INVALID_INDEX);
        }

        RowVector rv = new RowVector(nCols);
        for (int c = 0; c < nCols; ++c) {
            rv.values[0][c] = this.values[r][c];
        }

        return rv;
    }
1287403
public static RowMajorSparseMatrix from1DArray(int rows, int columns, double[] array) {
        return CRSMatrix.from1DArray(rows, columns, array);
    }
451941
def _indexes(arr):
    
    myarr = np.array(arr)
    if myarr.ndim == 1:
        return list(range(len(myarr)))
    elif myarr.ndim == 2:
        return tuple(itertools.product(list(range(arr.shape[0])),
                                       list(range(arr.shape[1]))))
    else:
        raise NotImplementedError('Only supporting arrays of dimension 1 and 2 as yet.')
1234343
public function forOrderThree()
    {
        if ($this->matrix->getNumRows()!==3) {
            throw new OperationNotAllowedException('determinantOrderThree only allowed on 3x3 matrix');
        }
        $additions = array(
            array(array(1,1), array(2,2), array(3,3)),
            array(array(1,2), array(2,3), array(3,1)),
            array(array(1,3), array(2,1), array(3,2)),
        );
        $subtractions = array(
            array(array(1,3), array(2,2), array(3,1)),
            array(array(1,2), array(2,1), array(3,3)),
            array(array(1,1), array(2,3), array(3,2)),
        );
        $result = $this->valueZero;
        foreach ($additions as $addition) {
            $partial = $this->valueOne;
            foreach ($addition as $point) {
                $partial = bcmul($partial, $this->matrix->getPoint($point[0], $point[1]), $this->precision);
            }
            $result = bcadd($result, $partial, $this->precision);
        }
        foreach ($subtractions as $subtraction) {
            $partial = $this->valueOne;
            foreach ($subtraction as $point) {
                $partial = bcmul($partial, $this->matrix->getPoint($point[0], $point[1]), $this->precision);
            }
            $result = bcsub($result, $partial, $this->precision);
        }
        return $result;
    }
847018
public static int stride(IntBuffer buffer, int dimension) {
        int rank = rank(buffer);
        if (dimension >= rank)
            throw new IllegalArgumentException("Invalid dimension " + dimension + " for rank " + rank + " array");
        return buffer.get(1 + rank + dimension);
    }
798219
static int[] rank(final int[][] g) {
        final int ord = g.length;

        final int[] count = new int[ord + 1];
        final int[] rank = new int[ord];

        // frequency of each degree
        for (int v = 0; v < ord; v++)
            count[g[v].length + 1]++;
        // cumulated counts
        for (int i = 0; count[i] < ord; i++)
            count[i + 1] += count[i];
        // store sorted position of each vertex
        for (int v = 0; v < ord; v++)
            rank[v] = count[g[v].length]++;

        return rank;
    }
107289
public static double[][] diag(double[] vector){

		// Note: According to the Java Language spec, an array is initialized with the default value, here 0.
		double[][] diagonalMatrix = new double[vector.length][vector.length];

		for(int index = 0; index < vector.length; index++) {
			diagonalMatrix[index][index] = vector[index];
		}

		return diagonalMatrix;
	}
405688
public static int get2DArrayXDim(final Object array2D) {
        int dimX = 0;
        if (Array.getLength(array2D) > 0) {
            dimX = Array.getLength(Array.get(array2D, 0));
        }
        return dimX;
    }
409040
public static int[] getDimensions( JSONArray jsonArray ) {
      // short circuit for empty arrays
      if( jsonArray == null || jsonArray.isEmpty() ){
         return new int[] { 0 };
      }

      List dims = new ArrayList();
      processArrayDimensions( jsonArray, dims, 0 );
      int[] dimensions = new int[dims.size()];
      int j = 0;
      for( Iterator i = dims.iterator(); i.hasNext(); ){
         dimensions[j++] = ((Integer) i.next()).intValue();
      }
      return dimensions;
   }
553451
public static long matricesPerSlice(INDArray arr) {
        if (arr.rank() == 3) {
            return 1;
        } else if (arr.rank() > 3) {
            int ret = 1;
            for (int i = 1; i < arr.rank() - 2; i++) {
                ret *= arr.size(i);
            }
            return ret;
        }
        return arr.size(-2);
    }
995932
private int getLeastCommonArrayLength(String[] arr1, String[] arr2) {
        return arr1.length <= arr2.length ? arr1.length : arr2.length;
    }
493333
private int[] findArrayDimensions(List<?> list, Class<?> arrayType) {
        List<int[]> elementDims = new LinkedList<int[]>();
        int dimCount = 0;
        for (Object o : list) {
            if (o != null && o.getClass().isArray() && 
                isAssignableFromArray(arrayType, o.getClass().getComponentType())) {
                final int[] dimensions = findArrayDimensions(o);
                elementDims.add(dimensions);
                dimCount = Math.max(dimCount, dimensions.length);
            }
        }

        int[] dimsArr = new int[dimCount + 1];
        // First dimension length is always size of given list
        dimsArr[0] = list.size();
        // Find the max length of each additional dimension
        for (int[] childDim : elementDims) {
            for (int i = 0; i < childDim.length; i++) {
                dimsArr[i + 1] = Math.max(dimsArr[i + 1], childDim[i]);
            }
        }
        return dimsArr;
    }
234982
public int rank() {
    final double eps = 0x1p-52, tol = (m > n ? m : n) * s[0] * eps;
    int r = 0;
    for(int i = 0; i < s.length; i++) {
      if(s[i] > tol) {
        r++;
      }
    }
    return r;
  }
163164
def vectors(self, array):
        
        if array.ndim != 2:
            raise AssertionError('vector array must be a 2-dimensional array')
        elif array.shape[1] != 3:
            raise RuntimeError('vector array must be 3D')
        elif array.shape[0] != self.n_points:
            raise RuntimeError('Number of vectors be the same as the number of points')

        self.point_arrays[DEFAULT_VECTOR_KEY] = array
        self.active_vectors_name = DEFAULT_VECTOR_KEY
673895
public static int count(float[] array, float val) {
        int count = 0;
        for (int i=0; i<array.length; i++) {
            if (array[i] == val) {
                count++;
            }
        }
        return count;
    }