Question: import java.util.ArrayList; public class ExtraMUtil { / * * * Performs element - wise addition of two matrices of the same shape. * @param 1

import java.util.ArrayList;
public class ExtraMUtil {
/**
* Performs element-wise addition of two matrices of the same shape.
* @param 1: A double[][] that represents a 2D matrix with shape m*n
* @param 2: A double[][] that represents a 2D matrix with shape m*n
* @return an ArrayList of double[] that represents the result 2D matrix with shape m*n.
*/
public static ArrayList matAddition(double[][] m1, double[][] m2){
// Fill your code here for completing the matrix addition operation
return null; // You can remove this line of "return null;"
}
/**
* Performs naive matrix multiplication between two matrices of shape [k][l] and [l][m]
* @param 1: An ArrayList of an ArrayList of Double that represents a 2D matrix with shape k*p
* @param 2: An ArrayList of double[] that represents a 2D matrix with shape p*m
* @return A double[][] that represents the result 2D matrix with shape k*m
*/
public static double[][] matProduct(ArrayList> m1, ArrayList m2){
// Fill your code here for completing the matrix multiplication operation
return null; // You can remove this line of "return null;"
}
/**
* Performs element-wise multiplication between two matrices and sums the result.
* @param 1: A double[][] that represents the first input matrix.
* @param 2: A double[][] that represents the second input matrix.
* @return a double[][] that represents the result matrix.
*/
public static double[][] matElemProduct(double[][] m1, double[][] m2){
// Fill your code here for completing the Element-wise matrix multiplication operation
return null; // You can remove this line of "return null;"
}
/**
* Sum the elements in a given 2D matrix
* @param 1: A double[][] that represents the input 2D matrix.
* @return a double that equals the sum of the elements in the matrix.
*/
public static double matSum(double[][] m){
// Fill your code here for completing the matrix sum operation
return 0; // You can remove this line of "return 0;"
}
/**
* Returns the transpose of a given 2D matrix with a shape of [m][n].
* @param 1: An ArrayList of ArrayList of Double that represents the input 2D matrix.
* @return a double[][] that represents the result 2D matrix with shape of n*m
*/
public static double[][] matTranspose(ArrayList> m){
// Fill your code here for completing the matrix transpose operation
return null; // You can remove this line of "return null;"
}
/**
* Returns a sub-matrix from a given 2D matrix with the specified range of indices.
* @param 1: An int that indicates the start row index.
* @param 2: An int that indicates the end row index.
* @param 3: An int that indicates the start column index.
* @param 4: An int that indicates the end column index.
* @param 5: A double[][] that represents the input 2D matrix.
* @return an ArrayList of double[] that represents the sub-matrix with shape (param2- param1+1)*(param4- param3+1)
*/
public static ArrayList subMat(int r_s, int r_e, int c_s, int c_e, double[][] m){
// Fill your code here for completing the sub-matrix extraction operation
return null; // You can remove this line of "return null;"
}
/**
* Flattens a 3D matrix of shape m by n by p into a vector of size m*n*p
* @param 1: a double[][][] that represents the input 3D matrix.
* @return a vector of size m*n*p
*/
public static double[] matToVec(double[][][] m){
// Fill your code here for completing the 3D matrix flatten operation.
return null; // You can remove this line of "return null;"
}
/**
* Reorganizes a vector to the desired 3D matrix of shape d by h by w.
* the size of the input vector must equal to d*h*w.
* @param 1: A double[] that represents the input vector.
* @param 2: An int that indicates the depth of the reshaped matrix.
* @param 3: An int that indicates the row size of the reshaped matrix.
* @param 4: An int that indicates the column size of the reshaped matrix.
* @return a 3D array of shape d by h by w
*/
public static double[][][] vecToMat(double[] input, int d, int h, int w){
// Fill your code here for completing the vector reshape operation
return null; // You can remove this line of "return null;"
}
/**
* Pretty prints a double type vector with the specified number of significant figures.
* @param 1: the input vector.
*/
public static void vecPrint(double[] v){
for (int j =0; j < v.length; j++){
System.out.prin

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!