【问题标题】:Julia - How to get the minimum of each row of matrix?Julia - 如何获得每行矩阵的最小值?
【发布时间】:2015-05-02 17:08:48
【问题描述】:

我尝试编写该代码,但它获取了行中最后一个索引的值

function heuristicCalculate(distanceBetweenCities,numOfCities) 
#distanceBetweenCities is a 29*29 array 
#Use this function to calculate the tour length using nearest neighbor heuristic Lnn
mindist=zeros(29,1)
  for i=1:29
    for j=1:29
    mindist[i,1]=Base.minimum(distanceBetweenCities[i,j])
    end
  end
  mindist
  return Lnn, tau0
  #Lnn  tour length using nearest neighbor heuristic
  #tau0  a value representing the initial phermone amount =1/(n*Lnn)
end

【问题讨论】:

    标签: for-loop multidimensional-array julia


    【解决方案1】:

    最简单的解决方案可能是

    mindist = minimum(distanceBetweenCities,2)
    

    ,2 表示搜索最小值的维度。

    【讨论】:

      猜你喜欢
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-14
      • 1970-01-01
      相关资源
      最近更新 更多