cummax
Cumulative maximum.
| Library |
|
Syntax
Function call
-
M = cummax(A)— returns the cumulative maximum elements of the arrayA.-
If
A— vector, thenM— a vector of the same size and type containing the cumulative maxima of the vectorA. -
If
A— the matrix, thenM— a matrix of the same size and type containing cumulative maxima in each column of the matrixA. -
If
A— a multidimensional array, thenM— an array of the same size and type containing cumulative maxima in the first dimension of the arrayA, the size of which is not equal to1.
-
Arguments
Input arguments
# A — input array
+
vector | the matrix | multidimensional array
Details
An input array specified as a vector, matrix, or multidimensional array. For complex elements, the function cummax compares their amplitudes. If the amplitudes are equal, cummax It also compares phase angles.
| Типы данных |
|
| Support for complex numbers |
Yes |
# dim — the measurement for which the operation is performed
+
a positive integer scalar
Details
The dimension that the operation is performed on, specified as a positive integer scalar. If no dimension is specified, the first dimension of the array is used by default, the size of which is not equal to 1.
Consider a two-dimensional input array A:
-
cummax(A,1)works with consecutive elements in columnsAand returns an array of the same size asA, with cumulative maxima in each column. -
cummax(A,2)works with consecutive elements in stringsAand returns an array of the same size asA, with cumulative maxima in each row.
cummax returns A if dim more than ndims(A).
# direction — cumulation direction
+
"forward" (by default) | "reverse"
Details
The direction of cumulation, set by one of the following values:
-
"forward"— work from1until the end of the working measurement; -
"reverse"— end-to-end work1working measurement.
# nanflag — condition for missing value
+
"omitmissing" (by default) | "omitnan" | "includemissing" | "includenan"
Details
The condition for processing a missing value, set by one of the following values:
-
"omitmissing"or"omitnan"— ignore the valuesNaNinAwhen calculating cumulative maxima. If inAthere are consecutive initial valuesNaN, then the corresponding elements inMThey are alsoNaN. Values"omitmissing"and"omitnan"they behave the same way. -
"includemissing"or"includenan"— enable valuesNaNinAwhen calculating cumulative maxima. Elements inMthey becomeNaNAs soon as inAthe first value occursNaN. Values"includemissing"and"includenan"they behave the same way.
Output arguments
# M — output array
+
vector | the matrix | multidimensional array
Details
The output array returned as a vector, matrix, or multidimensional array.
Examples
Cumulative maximum in the vector
Details
Let’s find the cumulative maximum of a vector of random integers of size 1 on 10.
import EngeeDSP.Functions: randi
v = randi([0,10],1,10)
1×10 Matrix{Float64}:
3.0 9.0 6.0 6.0 10.0 3.0 8.0 8.0 4.0 6.0
import EngeeDSP.Functions: cummax
M = cummax(v)
1×10 Matrix{Float64}:
3.0 9.0 6.0 6.0 10.0 3.0 8.0 8.0 4.0 6.0
Cumulative maximum in the columns of the matrix
Details
Let’s find the cumulative maximum of the columns of the matrix with the size 3×3.
A = [3 5 2; 1 6 3; 7 8 1]
3×3 Matrix{Int64}:
3 5 2
1 6 3
7 8 1
import EngeeDSP.Functions: cummax
M = cummax(A)
3×3 Matrix{Float64}:
3.0 5.0 2.0
3.0 6.0 3.0
7.0 8.0 3.0
Cumulative maximum in the rows of the matrix
Details
Let’s find the cumulative maximum of the rows of the matrix with the size 3×3.
A = [3 5 2; 1 6 3; 7 8 1]
3×3 Matrix{Int64}:
3 5 2
1 6 3
7 8 1
import EngeeDSP.Functions: cummax
M = cummax(A, 2)
3×3 Matrix{Float64}:
3.0 5.0 5.0
1.0 6.0 6.0
7.0 8.0 8.0
Reverse cumulative maximum
Details
Calculate the cumulative maximum in the third dimension of the array 2×2×3. We will indicate the direction "reverse" to calculate values from the end of the third dimension to the beginning.
A = cat([1 2; 3 4], [9 10; 11 12], [5 6; 7 8]; dims=3)
2×2×3 Array{Int64, 3}:
[:, :, 1] =
1 2
3 4
[:, :, 2] =
9 10
11 12
[:, :, 3] =
5 6
7 8
import EngeeDSP.Functions: cummax
M = cummax(A, 3, "reverse")
2×2×3 Array{Float64, 3}:
[:, :, 1] =
9.0 10.0
11.0 12.0
[:, :, 2] =
9.0 10.0
11.0 12.0
[:, :, 3] =
5.0 6.0
7.0 8.0
Cumulative maximum, including missing values
Details
Create a matrix containing the values NaN.
A = [3 5 NaN 4; 2 6 2 9; 1 3 0 NaN]
3×4 Matrix{Float64}:
3.0 5.0 NaN 4.0
2.0 6.0 2.0 9.0
1.0 3.0 0.0 NaN
Calculate the cumulative maxima of the matrix, including the values NaN. For matrix columns containing any value NaN, the cumulative maximum values become equal NaN as soon as the first value is encountered NaN.
import EngeeDSP.Functions: cummax
M = cummax(A, "includenan")
3×4 Matrix{Float64}:
3.0 5.0 NaN 4.0
3.0 6.0 NaN 9.0
3.0 6.0 NaN NaN