max


Julia: Find the indices of all maxima


In Julia you can use findmax or indmax to find the index of the biggest entry in a matrix. But if you have multiple entries with this maximum value, you get the index of the first one.
How can I get the indices of all max value entries in a matrix?
If this is not a bottleneck
A = [1, 2, 3, 3, 3]
A_max = maximum(A)
find(a->a==A_max, A)
Will give you what you need, but it does go over the array twice.
You can also use comprehensions. The array will be iterated twice.
v = [1, 2, 3, 3, 3]
maxval = maximum(v)
positions = [i for (i, x) in enumerate(v) if x == maxval]
If performance is critical then the following algorithm may work:
function findallmax(arr)
max_positions = Vector{Int}()
min_val = typemin(eltype(arr))
for i in eachindex(arr)
if arr[i] > min_val
min_val = arr[i]
empty!(max_positions)
push!(max_positions, i)
elseif arr[i] == min_val
push!(max_positions, i)
end
end
max_positions
end
one iteration is required.

Related Links

How to make the agent pick the highest value between two values?
Rendering Error 3ds max
Define a region in using MaxValue[] function in Mathematica
Is there any algorithm to find the maximum value of this?
ZoomRange Highstock works not correct?
XQuery find two largest values
Highstock custom min max approximation works properly only at some ranges
SPSS - declare and use maximum number of cases as a constant
XQuery: find max value and return relevant information
modelica: compute minimum/maximum of continuous variable over time
Find max indices in octave
Max MSP. How I initialize a BPM counter/ tempo recognizer with a massage if bmp changes?
MAX MSP // How can i controll visualisation with incoming audio signal?
Subset a data frame in R based on above and below a threshold value
Splunk argmax: get field value corresponding to max value of another field
How to determine the register with the greatest content

Categories

HOME
grizzly
qemu
latex
livecharts
query-string
css-selectors
swap
kohana
android-webview
promotions
token
oms
unreal-engine4
adroitlogic
jetbrains
minimum
openscad
openam
indri
aws-devicefarm
cherrypy
coccinelle
gnu-screen
procedural-generation
devexpress-mvc
my.cnf
datanucleus
nsopenpanel
sasl
libxml2
vtd-xml
opencsv
tikz
mplab
visual-studio-debugging
language-detection
slim-lang
multi-user
area
lex
sknode
socketcluster
vertical-alignment
test-kitchen
nshttpurlresponse
html-entities
activeandroid
cancan
dynamic-linking
richtext
wicketstuff
iban
vertex-shader
breadcrumbs
blitz3d
timefield
mongodb-3.3
eclipse-mars
dbi
scriptengine
jde
angular-i18n
user-profile
clique
cexception
custom-build-step
newlib
ios8-share-extension
adempiere
vensim
tidesdk
backtrace
pysvn
caption
go-gin
zoneminder
powerpoint-2010
parsefloat
pnunit
xts
step
satisfiability
sqldatasource
html5-filesystem
.net-reflector
vbaccelerator
xml-validation
tlbimp
objectdatasource
listpicker
record-locking
blotter
database-restore
django-tinymce
cron4j
libx264
configurationsection
openafs
expresso-store
netbiscuits
databus
sup
unordered-set
pinchzoom
yii-cactiverecord
recess
hwnd
viewdata
p4.net
manuals
authkit
urlscan
memory-consumption

Resources

Encrypt Message