Here you can find the source of vectorMagnitude4D(float[][][][] vec4D)
static public float[][][] vectorMagnitude4D(float[][][][] vec4D)
//package com.java2s; //License from project: Apache License public class Main { static public float[][][] vectorMagnitude4D(float[][][][] vec4D) { int rows = vec4D.length; int cols = vec4D[0].length; int slices = vec4D[0][0].length; int components = vec4D[0][0][0].length; float[][][] M = new float[rows][cols][slices]; double sum = 0; for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) for (int k = 0; k < slices; k++) { sum = 0;//from w ww .j a va 2 s .com for (int l = 0; l < components; l++) { sum += Math.pow(vec4D[i][j][k][l], 2); } M[i][j][k] = (float) Math.sqrt(sum); } return M; } }