public class DoubleMatrixND extends Object
Constructor and Description |
---|
DoubleMatrixND(Collection<? extends Number> values,
String rowOrColumn)
Creates a row or column (1xN, or Nx1) array, dense, with the given values
|
DoubleMatrixND(double value)
Creates a 1x1 dense array with the given value.
|
DoubleMatrixND(double[][] values)
Creates a 2D dense array, with the same size as value, and initializes with the data in values
|
DoubleMatrixND(double[][][] values)
Creates a 3D dense array, with the same size as value, and initializes with the data in values
|
DoubleMatrixND(double[][][][] values)
Creates a 4D dense array, with the same size as value, and initializes with the data in values
|
DoubleMatrixND(double[][][][] values,
String type)
Creates a 4D array of the appropriated type, with the same size as value, and initializes with the data in values
|
DoubleMatrixND(double[][][] values,
String type)
Creates a 3D array of the appropriated type, with the same size as value, and initializes with the data in values
|
DoubleMatrixND(double[][] values,
String type)
Creates a 2D array of the appropriated type, with the same size as value, and initializes with the data in values
|
DoubleMatrixND(double[] values,
String rowOrColumn)
Creates a row or column (1xN, or Nx1) array, dense, with the given values
|
DoubleMatrixND(DoubleMatrix2D values)
Creates a 2D array of the same type (sparse, dense) as values, and also with the same size and data
|
DoubleMatrixND(DoubleMatrix3D values)
Creates a 3D array of the same type (sparse, dense) as values, and also with the same size and data
|
DoubleMatrixND(int[] size)
Creates a dense empty array of the given size, initialized to zeros
|
DoubleMatrixND(int[] size,
double value)
Creates a dense array of the given size, initialized to value
|
DoubleMatrixND(int[] size,
double[] values)
Creates a dense array of the given size, using values as initializing data. values must be a vector of as many elements as the number of
cells in the array (product of the numbers in size parameter). i-th index in values vector is put in the array position of i-th linear index.
|
DoubleMatrixND(int[] size,
double[] values,
String type)
Creates an array of the given size and type, using values as initializing data. values must be a vector of as many elements as the number of
cells in the array (product of the numbers in size parameter). i-th index in values vector is put in the array position of i-th linear index
.
|
DoubleMatrixND(int[] size,
DoubleMatrix1D values)
Creates an array of the given size and the same type as values, using values as initializing data. values must have as many elements as the
number of cells in the array (product of the numbers in size parameter). i-th index in values vector is put in the array position of i-th
linear index.
|
DoubleMatrixND(int[] size,
double value,
String type)
Creates an array of the given size and type.
|
DoubleMatrixND(int[] size,
int[] values)
Creates a dense array of the given size, using values as initializing data, previously casted to double. values must be a vector of as many
elements as the number of cells in the array (product of the numbers in size parameter). i-th index in values vector is put in the array
position of i-th linear index.
|
DoubleMatrixND(int[] size,
int[] values,
String type)
Creates an array of the given size and type, using values as initializing data, previously casted to double. values must be a vector of as
many elements as the number of cells in the array (product of the numbers in size parameter). i-th index in values vector is put in the array
position of i-th linear index.
|
DoubleMatrixND(int[] size,
String type)
Creates an empty array of the given size and type, initialized to zeros
|
Modifier and Type | Method and Description |
---|---|
double |
aggregate(DoubleDoubleFunction aggr,
DoubleFunction f)
Applies a function to each cell and aggregates the results.
|
double |
aggregate(DoubleDoubleFunction aggr,
DoubleFunction f,
IntArrayList indexList)
Applies a function to all cells with the given indexes and aggregates the results
|
double |
aggregate(DoubleMatrixND other,
DoubleDoubleFunction aggr,
DoubleDoubleFunction f)
Applies a function to each corresponding cell of two matrices and aggregates the results.
|
DoubleMatrixND |
ascending(double first,
double step)
Fills the current array with ascending numbers (in the order of the linear indexes)
|
DoubleMatrixND |
assign(double value)
Sets all cells to the state specified by value
|
DoubleMatrixND |
assign(double[] values)
Sets all cells to the state specified by values. values is required to have as many cells as this.
|
DoubleMatrixND |
assign(DoubleFunction f)
Assigns the result of a function to each cell. x[i] = function(x[i]).
|
DoubleMatrixND |
assign(DoubleMatrixND other)
Replaces all cell values of the receiver with the values of another matrix.
|
DoubleMatrixND |
assign(DoubleMatrixND y,
DoubleDoubleFunction function)
Assigns the result of a function to each cell; x[i] = function(x[i],y[i]).
|
DoubleMatrixND |
assign(DoubleMatrixND y,
DoubleDoubleFunction function,
IntArrayList indexList)
Assigns the result of a function to all cells with a given indexes function - a function object taking as first argument the current cell's
value of this, and as second argument the current cell's value of y
|
DoubleMatrixND |
assign(DoubleProcedure cond,
double value)
Assigns a value to all cells that satisfy a condition.
|
DoubleMatrixND |
assign(DoubleProcedure cond,
DoubleFunction f)
Assigns the result of a function to all cells that satisfy a condition.
|
int |
cardinality()
Returns the number of cells having non-zero values; ignores tolerance
|
DoubleMatrixND |
copy()
Constructs and returns a deep copy of the receiver.
|
DoubleMatrixND |
descending(double first,
double step)
Fills the current array with descending numbers (in the order of the linear indexes)
|
DoubleMatrix1D |
elements()
Returns the elements of this matrix
|
boolean |
equals(double value)
Returns whether all cells are equal to the given value
|
boolean |
equals(DoubleMatrixND other)
Compares this object against the specified object.
|
double |
get(int index)
Returns the matrix cell value at the given index.
|
double |
get(int[] subindexes)
Returns the matrix cell value at the given subindexes
|
double[] |
getMaxLocation()
Return maximum value of this matrix together with its location.
|
double[] |
getMinLocation()
Return minimum value of this matrix together with its location.
|
void |
getNegativeValues(IntArrayList indexList,
DoubleArrayList valueList)
Fills the indexes and values of cells having negative values into the specified lists.
|
void |
getNonZeros(IntArrayList indexList,
DoubleArrayList valueList)
Fills the indexes and values of cells having non zero values into the specified lists.
|
int |
getNumberOfNonZeros()
Returns the number of non zero elements
|
int |
getNumDim()
Gets the number of dimensions of the array
|
int |
getNumElements()
Gets the number of cells in the array (e.g for an array of size 2x3x5 the number of cells is 30)
|
void |
getPositiveValues(IntArrayList indexList,
DoubleArrayList valueList)
Fills the indexes and values of cells having positive values into the specified lists.
|
double |
getQuick(int index)
Returns the matrix cell value at coordinate index.
|
IntMatrix1D |
getSize()
Gets the size of the array
|
int |
getSize(int dim)
Gets the size of the array in the given dimension
|
static IntMatrix2D |
ind2sub(int[] indexes,
int[] size)
For arrays of the given size, converts the positions of the cells given as a linear index in indexes, into their associated coordinates in
the arrays.
|
static IntMatrix1D |
ind2sub(int index,
int[] size)
For arrays of the given size, converts the position of a cell given as a linear index, into its associated coordinates in the arrays.
|
boolean |
isView()
Returns whether the receiver is a view or not.
|
void |
normalize()
Normalizes this matrix, i.e. makes the sum of all elements equal to 1.0 If the matrix contains negative elements then all the values are
shifted to ensure non-negativity.
|
DoubleMatrixND |
reshape(int[] newSize)
Changes the shape of this array.
|
void |
set(int[] subindexes,
double value)
Sets the matrix cell at coordinate given by the subindexes to the specified value.
|
void |
set(int index,
double value)
Sets the matrix cell at coordinate given by the subindexes to the specified value.
|
void |
setQuick(int[] subindexes,
double value)
Sets the matrix cell at coordinate given by the subindexes to the specified value.
|
void |
setQuick(int index,
double value)
Sets the matrix cell at coordinate index to the specified value.
|
static int |
sub2ind(IntMatrix1D coord,
int[] size)
For arrays of the given size, converts the position of the cell given as a their coordinates, into its associated linear index.
|
static IntMatrix1D |
sub2ind(IntMatrix2D coord,
int[] size)
For arrays of the given size, converts the positions of the cells given as a their coordinates, into their associated linear index.
|
double[] |
to1DArray()
Constructs and returns a 1-dimensional array containing the array values.
|
double[][] |
to2DArray()
Constructs and returns a 2-dimensional array containing the array values.
|
double[][][] |
to3DArray()
Constructs and returns a 3-dimensional array containing the array values.
|
double[][][][] |
to4DArray()
Constructs and returns a 4-dimensional array containing the array values.
|
double[][][][][] |
to5DArray()
Constructs and returns a 5-dimensional array containing the array values.
|
double[][][][][][] |
to6DArray()
Constructs and returns a 5-dimensional array containing the array values.
|
Object |
toArray()
Constructs and returns an n-dimensional double array containing the array values.
|
List<Double> |
toList()
Returns a List (ArrayList) with the values copied
|
String |
toString() |
double |
toValue()
If the array has only one cell, returns its value.
|
DoubleMatrix1D |
view1D()
If the array is 2D, returns a DoubleMatrix2D object copying the data in the array
|
DoubleMatrix2D |
view2D()
If the array is 2D, returns a DoubleMatrix2D object copying the data in the array
|
DoubleMatrix3D |
view3D(String type)
If the array is 3D, returns a DoubleMatrix3D object copying the data in the array
|
DoubleMatrixND |
viewPart(IntMatrix1D initialSubindex,
IntMatrix1D width)
Returns Constructs and returns a new sub-range view.
|
DoubleMatrixND |
viewSelection(IntMatrix1D[] subindexesPerDim)
Returns Constructs and returns a new sub-range view.
|
DoubleMatrixND |
viewSelectionByIndexes(int[] newSize,
IntMatrix1D indexes)
Returns Constructs and returns a new sub-range view.
|
double |
zSum()
Returns the sum of all cells in the array
|
public DoubleMatrixND(double value)
value
- The initializing datapublic DoubleMatrixND(double[][] values)
values
- The initializing datapublic DoubleMatrixND(double[] values, String rowOrColumn)
values
- the valuesrowOrColumn
- "row" for a row vector, "column" or other string for a column vectorpublic DoubleMatrixND(Collection<? extends Number> values, String rowOrColumn)
values
- the valuesrowOrColumn
- "row" for a row vector, "column" or other string for a column vectorpublic DoubleMatrixND(double[][] values, String type)
values
- The initializing datatype
- "sparse" or "dense" for creating sparse or dense arrays respectivelypublic DoubleMatrixND(double[][][] values)
values
- The initializing datapublic DoubleMatrixND(double[][][] values, String type)
values
- The initializing datatype
- "sparse" or "dense" for creating spavaluesrse or dense arrays respectivelypublic DoubleMatrixND(double[][][][] values)
values
- The initializing datapublic DoubleMatrixND(double[][][][] values, String type)
values
- The initializing datatype
- "sparse" or "dense" for creating sparse or dense arrays respectivelypublic DoubleMatrixND(DoubleMatrix2D values)
values
- The initializing datapublic DoubleMatrixND(DoubleMatrix3D values)
values
- The initializing datapublic DoubleMatrixND(int[] size)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.public DoubleMatrixND(int[] size, double value)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.value
- The initializing datapublic DoubleMatrixND(int[] size, double value, String type)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.value
- The initializing datatype
- "sparse" or "dense" for creating sparse or dense arrays respectivelypublic DoubleMatrixND(int[] size, double[] values)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.values
- The initializing datapublic DoubleMatrixND(int[] size, double[] values, String type)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.values
- The initializing datatype
- "sparse" or "dense" for creating sparse or dense arrays respectivelypublic DoubleMatrixND(int[] size, DoubleMatrix1D values)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.values
- The initializing datapublic DoubleMatrixND(int[] size, int[] values)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.values
- The initializing datapublic DoubleMatrixND(int[] size, int[] values, String type)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.values
- The initializing datatype
- "sparse" or "dense" for creating sparse or dense arrays respectivelypublic DoubleMatrixND(int[] size, String type)
size
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.type
- "sparse" or "dense" for creating sparse or dense arrays respectively. "random" for creating a matrix with random numbers
between 0 and 1 sampled from a uniform distributionpublic static IntMatrix1D ind2sub(int index, int[] size)
index
- Linear index of the cell positionsize
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.public static IntMatrix2D ind2sub(int[] indexes, int[] size)
indexes
- Linear indexes of the cells to convertsize
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.public static int sub2ind(IntMatrix1D coord, int[] size)
coord
- Coordinates of the cell positionsize
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.public static IntMatrix1D sub2ind(IntMatrix2D coord, int[] size)
coord
- Coordinates of the cell position. Each row is a coordinatesize
- Array size. The i-th element in size indicates the size of the array in the corresponding dimension.public double aggregate(DoubleDoubleFunction aggr, DoubleFunction f)
aggr
- an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell
value.f
- a function transforming the current cell value.public double aggregate(DoubleDoubleFunction aggr, DoubleFunction f, IntArrayList indexList)
aggr
- an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell
value.f
- a function transforming the current cell valueindexList
- indexes of the cellspublic double aggregate(DoubleMatrixND other, DoubleDoubleFunction aggr, DoubleDoubleFunction f)
other
- the second array to make the aggregationaggr
- an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell
valuesf
- a function transforming the current cell valuespublic DoubleMatrixND ascending(double first, double step)
first
- First number, assigned to index 0 of the arraystep
- step between the values in two consecutive cellspublic DoubleMatrixND assign(double value)
value
- the value to be filled into the cellspublic DoubleMatrixND assign(double[] values)
values
- the values to be filled into the cells.public DoubleMatrixND assign(DoubleFunction f)
f
- a function object taking as argument the current cell's value.public DoubleMatrixND assign(DoubleMatrixND other)
other
- the source matrix to copy from (may be identical to the receiver).public DoubleMatrixND assign(DoubleMatrixND y, DoubleDoubleFunction function)
y
- the secondary array to operate on.function
- a function object taking as first argument the current cell's value of this, and as second argument the current cell's value
of y,public DoubleMatrixND assign(DoubleMatrixND y, DoubleDoubleFunction function, IntArrayList indexList)
y
- the secondary array to operate onfunction
- a function object taking as first argument the current cell's value of this, and as second argument the current cell's value
of y,indexList
- the list of indexespublic DoubleMatrixND assign(DoubleProcedure cond, double value)
cond
- a conditionvalue
- a valuepublic DoubleMatrixND assign(DoubleProcedure cond, DoubleFunction f)
cond
- a conditionf
- a function objectpublic int cardinality()
public DoubleMatrixND copy()
public DoubleMatrixND descending(double first, double step)
first
- First number, assigned to index 0 of the arraystep
- step between the values in two consecutive cellspublic DoubleMatrix1D elements()
public boolean equals(double value)
value
- the value to test against.public boolean equals(DoubleMatrixND other)
other
- the object to compare withpublic double get(int index)
index
- the index of the cellpublic double get(int[] subindexes)
subindexes
- the coordinates of the cellpublic double[] getMaxLocation()
public double[] getMinLocation()
public void getNegativeValues(IntArrayList indexList, DoubleArrayList valueList)
indexList
- the list to be filled with the indexes, can have any sizevalueList
- the list to be filled with values, can have any sizepublic void getNonZeros(IntArrayList indexList, DoubleArrayList valueList)
indexList
- the list to be filled with the indexes, can have any sizevalueList
- the list to be filled with values, can have any sizepublic int getNumberOfNonZeros()
public int getNumDim()
public int getNumElements()
public void getPositiveValues(IntArrayList indexList, DoubleArrayList valueList)
indexList
- the list to be filled with the indexes, can have any sizevalueList
- the list to be filled with values, can have any sizepublic double getQuick(int index)
index
- the index of the cellpublic IntMatrix1D getSize()
public int getSize(int dim)
dim
- Dimension from which the size will be taken.public boolean isView()
public void normalize()
public DoubleMatrixND reshape(int[] newSize)
newSize
- new size of the array. The array must have the same number of cellspublic void set(int index, double value)
index
- the index of the cell.value
- the value to be filled into the specified cell.public void set(int[] subindexes, double value)
subindexes
- the cell coordinatesvalue
- the value to be filled into the specified cell.public void setQuick(int index, double value)
index
- the index of the cell.value
- the value to be filled into the specified cellpublic void setQuick(int[] subindexes, double value)
subindexes
- the coordinates of the cell.value
- the value to be filled into the specified cellpublic double[] to1DArray()
public double[][] to2DArray()
public double[][][] to3DArray()
public double[][][][] to4DArray()
public double[][][][][] to5DArray()
public double[][][][][][] to6DArray()
public Object toArray()
public double toValue()
public List<Double> toList()
public DoubleMatrix2D view2D()
public DoubleMatrix1D view1D()
public DoubleMatrix3D view3D(String type)
type
- Type of the matrix.public DoubleMatrixND viewPart(IntMatrix1D initialSubindex, IntMatrix1D width)
initialSubindex
- The coordinates of the cell that will is the upper-left corner of the subrange. This cell will have index 0 in the new
view.width
- For each dimension, its size in the new view.public DoubleMatrixND viewSelection(IntMatrix1D[] subindexesPerDim)
subindexesPerDim
- One IntMatrix1D object for each dimension, containing the indexes in the subrange.public DoubleMatrixND viewSelectionByIndexes(int[] newSize, IntMatrix1D indexes)
newSize
- The new size of the array. The associated number of cells in the new array must be equal to the number of indexes in indexesindexes
- An array with the inedexes to include in the view (in the same order as they appear here)public double zSum()
Copyright © 2018. All rights reserved.