Java Square Calculate square2array(byte[][] square)

Here you can find the source of square2array(byte[][] square)

Description

squarearray

License

Apache License

Declaration

public static byte[] square2array(byte[][] square) 

Method Source Code

//package com.java2s;
/*=========================================================================
 *
 *  Copyright (c) Karl T. Diedrich /*  w  w w  .  j ava  2  s .c  o m*/
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

public class Main {
    public static byte[] square2array(byte[][] square) {
        int height = square.length;
        int width = square[0].length;

        byte[] ar = new byte[height * width];
        int i = 0;
        for (int r = 0; r < height; r++) {
            for (int c = 0; c < width; c++) {
                ar[i] = square[r][c];
                i++;
            }
        }
        return ar;

    }

    public static short[] square2array(short[][] square) {
        int height = square.length;
        int width = square[0].length;

        short[] ar = new short[height * width];
        int i = 0;
        for (int r = 0; r < height; r++) {
            for (int c = 0; c < width; c++) {
                ar[i] = square[r][c];
                i++;
            }
        }
        return ar;

    }

    public static float[] square2array(float[][] square) {
        int height = square.length;
        int width = square[0].length;

        float[] ar = new float[height * width];
        int i = 0;
        for (int r = 0; r < height; r++) {
            for (int c = 0; c < width; c++) {
                ar[i] = square[r][c];
                i++;
            }
        }
        return ar;

    }
}

Related

  1. square2Index(long square)
  2. squareArea(final double side)
  3. squared(int x)
  4. squaredError(double[] vector1, double[] vector2)