median!
median!(v)
Like median
, but may overwrite the input vector.
Examples
-
Calculate the median of an array:
julia> arr = [5, 2, 8, 1, 9]; julia> median!(arr) 5
This example calculates the median of the array
arr
and overwrites the input vector with the result. -
Calculate the median of a vector of floats:
julia> data = [3.2, 1.8, 4.5, 2.7, 5.1]; julia> median!(data) 3.2
It calculates the median of the vector
data
and modifies the vector in place. - Calculate the median of a matrix along a specific dimension:
julia> matrix = [1 2 3; 4 5 6; 7 8 9]; julia> median!(matrix, dims=2) 3×1 Array{Int64,2}: 2 5 8
This example calculates the median along the second dimension (columns) of the matrix
matrix
and updates the matrix in place.
Common mistake example:
julia> arr = [5, 2, 8, 1, 9];
julia> median!(arr, dims=2)
ERROR: MethodError: no method matching median!(::Array{Int64,1}; dims=2)
In this example, the dims
argument is used incorrectly with median!
. The median!
function does not accept the dims
keyword argument. Ensure that you are using the correct arguments and options for the median!
function.
See Also
cummax, eigmax, findmax, hist, hist!, hist2d, hist2d!, histrange, indmax, maxabs, maxabs!, maximum!, mean, mean!, median, median!, minabs, minabs!, minimum!, minmax, quantile!, realmax, std, stdm,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.