public class IntegerArray extends Object
| Constructor and Description |
|---|
IntegerArray() |
| Modifier and Type | Method and Description |
|---|---|
static int[] |
copy(int[] M)
Generate a copy of an array
|
static int[][] |
copy(int[][] M)
Generate a copy of a matrix
|
static int[] |
cumProduct(int[] v)
Calculates cumulative product of the values in an array.
|
static int[][] |
cumProduct(int[][] v)
Calculates the cumulative product of each column in a matrix.
|
static int[] |
cumSum(int[] v)
Calculates the cumulative sum of an array.
|
static int[][] |
cumSum(int[][] v)
Calculates the cumulative sum of each column in a matrix.
|
static int[] |
delete(int[] x,
int... J)
Delete a list of elements from an array.
|
static int[][] |
deleteColumns(int[][] x,
int... J)
Deletes a list of columns from a matrix.
|
static int[][] |
deleteColumnsRange(int[][] x,
int J1,
int J2)
Deletes a range of columns from a matrix.
|
static int[] |
deleteRange(int[] x,
int J1,
int J2)
Delete a range of elements from an array.
|
static int[][] |
deleteRows(int[][] x,
int... I)
Deletes a list of rows from a matrix.
|
static int[][] |
deleteRowsRange(int[][] x,
int I1,
int I2)
Deletes a range of rows from a matrix.
|
static int[][] |
diagonal(int m,
int c)
Returns an m x m matrix. result has constants along the diagonal
and zeros everywhere else.
|
static int[] |
fill(int m,
int c)
Generates an m point array of constants
|
static int[][] |
fill(int m,
int n,
int c)
Returns an mxn matrix of constants
|
static int[] |
floor(double[] v)
Truncates each double value in an array to an integer that is less than or equal to the double.
|
static int[][] |
floor(double[][] v)
Truncates each double value in a matrix to an integer that is less than or equal to the double.
|
static int[] |
getColumnCopy(int[][][] M,
int j,
int k)
Extract one column from a three dimensional array.
|
static int[] |
getColumnCopy(int[][] M,
int j)
Extract one column from a matrix.
|
static int |
getColumnDimension(int[][] M,
int i)
Get the number of columns in a specified row of a matrix.
|
static int[][] |
getColumnsCopy(int[][] M,
int... J)
Extract specific columns from a matrix.
|
static int[][] |
getColumnsRangeCopy(int[][] M,
int j1,
int j2)
Extract a range of columns from a matrix.
|
static int[] |
getCopy(int[] M,
int... I)
Extract specific elements from an array.
|
static int[] |
getDiagonal(int[][] M,
int I)
Extract diagonal from a matrix.
|
static int[] |
getRangeCopy(int[] M,
int j1,
int j2)
Extract a section of an array.
|
static int[] |
getRowCopy(int[][] M,
int i)
Extract a row from a matrix.
|
static int[][] |
getRowsCopy(int[][] M,
int... I)
Extract specific rows from a matrix.
|
static int[][] |
getRowsRangeCopy(int[][] M,
int i1,
int i2)
Extract a range of rows from a matrix.
|
static int[][] |
getSubMatrixRangeCopy(int[][] M,
int i1,
int i2,
int j1,
int j2)
Carve out a submatrix from the input matrix and return a copy.
|
static int[] |
insert(int[] x,
int I,
int... y)
Insert any number of values, or a single array, between 2 elements of an array.
|
static int[][] |
insertColumns(int[][] x,
int J,
int[]... y)
Insert any number of arrays between 2 columns of a matrix.
|
static int[][] |
insertRows(int[][] x,
int I,
int[]... y)
Insert any number of arrays between 2 rows of a matrix.
|
static double[] |
int2double(int[] v)
Converts each element in an integer array to a double
|
static double[][] |
int2double(int[][] v)
Converts each element in an integer matrix to a double
|
static int |
max(int... M)
Finds maximum value in either a list of numbers or a single array.
|
static int[] |
max(int[][] M)
Finds the maximum value in each column of a matrix.
|
static int |
maxIndex(int... M)
Finds the index of the maximum value in a list of values or an array.
|
static int[] |
maxIndex(int[][] M)
Finds the indices of the maximum values in each column of a matrix.
|
static int[] |
merge(int[]... x)
Concatenates arrays.
|
static int[][] |
mergeColumns(int[]... x)
Combine a set of arrays into a matrix.
|
static int[][] |
mergeRows(int[]... x)
Combine a set of arrays into a matrix.
|
static int |
min(int... M)
Finds minimum value in either a list of numbers or a single array.
|
static int[] |
min(int[][] M)
Finds the minimum value in each column of a matrix.
|
static int |
minIndex(int... M)
Finds the index of the minumum value in a list of values or an array.
|
static int[] |
minIndex(int[][] M)
Finds the indices of the minimum values in each column of a matrix.
|
static int |
product(int[] v)
Calculates the product of the values in an array.
|
static int[] |
product(int[][] v)
Calculates the product of the values in each column of a matrix.
|
static int |
sum(int[] v)
Calculate the sum of the values in an array
|
static int[] |
sum(int[][] v)
Calculates the sum of each column in a matrix.
|
static String |
toString(int[]... v)
Generates a string that holds a nicely organized version of a matrix or array.
|
static String |
toString(String format,
int[]... v)
Generates a string that holds a nicely organized version of a matrix or array.
|
static int[][] |
transpose(int[][] M)
Transposes an mxn matrix into an nxm matrix.
|
public static int[][] diagonal(int m,
int c)
m - an integer > 0.c - Constant that lies along diagonal. Set c=1 for identity matrix.public static int[][] fill(int m,
int n,
int c)
m - number of rows in matrixn - number of columns in matrixc - constant matrix is filled with.public static int[] fill(int m,
int c)
m - Size of arrayc - constant array is to be filled withpublic static int[][] floor(double[][] v)
v - The input matrix of doublespublic static int[] floor(double[] v)
v - The input array of doublespublic static double[][] int2double(int[][] v)
v - matrix of integerspublic static double[] int2double(int[] v)
v - array of integerspublic static int[] copy(int[] M)
M - Input array.public static int[][] copy(int[][] M)
M - Input matrix.public static int[][] getSubMatrixRangeCopy(int[][] M,
int i1,
int i2,
int j1,
int j2)
int[][] a =
{{0,1,2,3,4},
{1,7,8,9,10},
{2,13,14,15,16},
{3,19,20,21,22},
{4,25,26,27,28}};
int[][] b = getSubMatrixRangeCopy(a, 2, 3, 1, 3);
Result is:
13 14 15
19 20 21
M - Input matrixi1 - first row in cuti2 - last row in cutj1 - first column in cutj2 - last column in cutpublic static int[][] getColumnsRangeCopy(int[][] M,
int j1,
int j2)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
int[][] z = getColumnsRangeCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 3 4
8 9 10
14 15 16
20 21 22
26 27 28
M - Input matrixj1 - Index of first column to be extracted.j2 - Index of last column to be extracted.public static int[][] getColumnsCopy(int[][] M,
int... J)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
int[][] z = getColumnsCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
0 2 4
1 8 10
2 14 16
3 20 22
4 26 28
M - Input matrixJ - Each is the index of a column. There can be as many indices listed as there are columns in M.public static int[] getColumnCopy(int[][] M,
int j)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
int[][] z = getColumnCopy(a, 2);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
Result is:
2 8 14 20 26
M - Input matrixj - Index of desired columnpublic static int[] getColumnCopy(int[][][] M,
int j,
int k)
M - Input 3D arrayj - The index of the second dimension.k - The index of the third dimensionpublic static int[][] getRowsCopy(int[][] M,
int... I)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
int[][] z = getRowsCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 13 14 15 16
4 25 26 27 28
M - Input matrixI - Each is the index of a column. There can be as many indices listed as there are rows in M.public static int[] getRowCopy(int[][] M,
int i)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
int[] z = getRowCopy(a, 2);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 13 14 15 16
M - Input matrixi - index of row to copypublic static int[][] getRowsRangeCopy(int[][] M,
int i1,
int i2)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
int[][] z = getRowsRangeCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
M - Input matrixi1 - Index of first row to be extracted.i2 - Index of last row to be extracted.public static int[] getRangeCopy(int[] M,
int j1,
int j2)
int[] a = {00,11,22,33,44,55,66,77,88,99};
int[] z = getRangeCopy(a, 2, 5);
result is:
22 33 44 55
M - Input arrayj1 - Index of first term to getj2 - Index of last term to getpublic static int[] getCopy(int[] M,
int... I)
int[] a = {00,11,22,33,44,55,66,77,88,99};
int[] z = getCopy(a, 2, 5);
result is:
22 55
M - The input array.I - the indices of the elements to extractpublic static int getColumnDimension(int[][] M,
int i)
M - Input matrixi - Index of row whose column length will be returnedpublic static int[] getDiagonal(int[][] M,
int I)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
int[] z = getDiagonal(a, 1);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
1 8 15 22
M - Input matrixI - index of diagonal to copypublic static int[][] mergeRows(int[]... x)
int[] a = {0,11,22,33,44}, b = {55,66,77,88};
int[][] z = mergeRows(a, b);
result is:
0 11 22 33 44
55 66 77 88
x - Input arrayspublic static int[][] mergeColumns(int[]... x)
int[] a = {00,11,22,33,44}, b = {55,66,77,88,99};
int[][] z = mergeColumns(a, b);
result is:
0 55
11 66
22 77
33 88
44 99
x - Input arrayspublic static int[] merge(int[]... x)
int[] a = {00,11,22,33,44}, b = {55,66,77,88,99};
int[] z = merge(a, b, a);
result is:
0 11 22 33 44 55 66 77 88 99 0 11 22 33 44
x - Input arrayspublic static int[][] insertColumns(int[][] x,
int J,
int[]... y)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
int[] b = {00,11,22,33,44}, c = {55,66,77,88,99};
int[][] z = insertColumns(a, 2, b, c);
input matrix is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 23 24 25 26
result is:
0 1 0 55 2 3 4
1 7 11 66 8 9 10
2 13 22 77 14 15 16
3 19 33 88 20 21 22
4 23 44 99 24 25 26
x - Input m x n matrix.J - Index of column before which the new columns will be inserted.y - The arrays to be insertedpublic static int[][] insertRows(int[][] x,
int I,
int[]... y)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22}};
int[] b = {0,11,22,33,44}, c = {55,66,77,88,99};
int[][] z = insertRows(a, 1, b, c);
result is:
0 1 2 3 4
0 11 22 33 44
55 66 77 88 99
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
x - Input m x n matrix.I - Index of row before which the new rows will be inserted.y - The arrays to be insertedpublic static int[] insert(int[] x,
int I,
int... y)
int[] b = {00,11,22,33,44}, c = {55,66,77,88,99};
int[] z = insert(b, 2, 333, 444);
result is:
0 11 333 444 22 33 44
int[] z = insert(b, 2, c);
result is:
0 11 55 66 77 88 99 22 33 44
x - Input array.I - Index of element before which the values will be inserted.y - Values to be inserted. Can also be a single array.public static int[][] deleteColumnsRange(int[][] x,
int J1,
int J2)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
int[][] z = deleteColumnsRange(a, 1, 3);
result is:
0 4
1 10
2 16
3 22
4 26
x - The input matrixJ1 - The Index of the first column to delete.J2 - The index of the last column to delete.public static int[][] deleteColumns(int[][] x,
int... J)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
int[][] z = deleteColumns(a, 1, 3);
result is:
0 2 4
1 8 10
2 14 16
3 20 22
4 24 26
x - The input matrixJ - The indices of the columns to be deleted. There must be no more indices listed
than there are columns in the input matrix.public static int[][] deleteRowsRange(int[][] x,
int I1,
int I2)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
int[][] z = deleteRowsRange(a, 1, 3);
result is:
0 1 2 3 4
4 23 24 25 26
x - The input matrixI1 - The Index of the first row to delete.I2 - The index of the last row to delete.public static int[][] deleteRows(int[][] x,
int... I)
int[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
int[][] z = deleteRows(a, 1, 3);
result is:
0 1 2 3 4
2 13 14 15 16
4 23 24 25 26
x - The input matrixI - The indices of the rows to delete.public static int[] deleteRange(int[] x,
int J1,
int J2)
int[] b = {00,11,22,33,44};
int[] z = deleteRange(b, 1, 3);
Result is:
0 44
x - Input arrayJ1 - Index of first element to delete. Must be > = 0 and < = x.lengthJ2 - Index of last element to delete. Must be >= J1 and < = x.lengthpublic static int[] delete(int[] x,
int... J)
int[] b = {00,11,22,33,44};
int[] z = deleteRange(b, 1, 3);
Result is:
0 22 44
x - Input arrayJ - Index of elements to delete. Each must be > = 0 and < x.lengthpublic static int[] min(int[][] M)
int[][] a = {{0, 13, 22, 3, 44},
{1, 7, 28, 9, 10},
{2, 1, 14, 15, 6},
{3, 19, 20, 21, 2},
{4, 23, 24, 25, 6}};
int[] z = min(a);
Result is:
0 1 14 3 2
M - The input matrixpublic static int min(int... M)
M - Can be a list of values e.g. min(1,22,333,.4) or an array.public static int[] max(int[][] M)
int[][] a = {{0, 1, 2, 3, 4},
{1, 7, 88, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 201, 22},
{4, 23, 24, 25, 26}};
int[] z = max(a);
Result is:
4 23 88 201 26
M - The input matrixpublic static int max(int... M)
M - Can be a list of values e.g. min(1,22,333,.4) or an array.public static int[] minIndex(int[][] M)
int[][] a = {{0, 13, 22, 3, 44},
{1, 7, 28, 9, 10},
{2, 1, 14, 15, 6},
{3, 19, 20, 21, 2},
{4, 23, 24, 25, 6}};
int[] z = minIndex(a);
Result is:
0 2 2 0 3
M - Input matrix.public static int minIndex(int... M)
M - Can be a list of values e.g. minIndex(11,22,44,2) or an arraypublic static int[] maxIndex(int[][] M)
int[][] a = {{0, 1, 2, 3, 4},
{1, 7, 88, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 201, 22},
{4, 23, 24, 25, 26}};
int[] z = maxIndex(a);
Result is:
4 4 1 3 4
M - Input matrix.public static int maxIndex(int... M)
M - Can be a list of values e.g. maxIndex(11,22,44,2) or an arraypublic static int sum(int[] v)
v - input arraypublic static int[] sum(int[][] v)
v - public static int[] cumSum(int[] v)
int[] b = {0,1,2,3,4};
int[] z = cumSum(b);
result is:
0 1 3 6 10
v - Input array.public static int[][] cumSum(int[][] v)
int[][] a = {{0, 1, 2, 3, 4},
{1, 7, 8, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 21, 22},
{4, 23, 24, 25, 26}};
int[][] z = cumSum(a);
result is:
0 1 2 3 4
1 8 10 12 14
3 21 24 27 30
6 40 44 48 52
10 63 68 73 78
v - public static int product(int[] v)
v - Input array.public static int[] product(int[][] v)
v - Input matrix.public static int[] cumProduct(int[] v)
int[] b = {1,2,3,4};
int[] z = cumProduct(b);
Result is:
1 2 6 24
v - Input arraypublic static int[][] cumProduct(int[][] v)
int[][] a = {{0, 1, 2, 3, 4},
{1, 7, 8, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 21, 22},
{4, 23, 24, 25, 26}};
Result is:
0 1 2 3 4
0 7 16 27 40
0 91 224 405 640
0 1729 4480 8505 14080
0 39767 107520 212625 366080
v - public static String toString(int[]... v)
int[][] a = {{1,22,333},{4444,555,7}};
System.out.println(tostring(a));
result is:
1 22 333
4444 555 7
v - Matrix or arraypublic static String toString(String format, int[]... v)
int[][] a = fill(2, 3, 555);
System.out.println(tostring("%11d", a));
result is:
555 555 555
555 555 555
format - A standard format specifier for one valuev - Matrix or arraypublic static int[][] transpose(int[][] M)
M - Input matrix.Copyright © 2015. All rights reserved.