Первый Массив С Наименьшей Плотностью В многомерном массиве

#vb.net #probability-density

Вопрос:

Я пытаюсь найти наименьшую плотность в многомерном массиве.

Допустим, массив выглядит следующим образом

 1 1 1 1 1 lt;- Lowest density is this one row:1 column:2. 1 1 1  
 1 1 1 1 1 1 lt;- Lowest density is this one row 2: column:1.  

Вот мой сломанный код

 Public ProcessedBits()() As Byte  'Lowest Density detector to find out which values have the highest priority. Dim nextLowestDensityColumn As Integer = Integer.MaxValue Dim nextLowestDensityRow As Integer = Integer.MaxValue  For Row = 0 To Uniques.Length - 1  For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.  If ProcessedBits(Row)(Column) = 1 Then 'if the column is processed, then skip it and process the next one.  If Column lt; nextLowestDensityColumn AndAlso Row lt; nextLowestDensityRow Then  nextLowestDensityColumn = Column   1  nextLowestDensityRow = Row  End If  End If  Next Next  If nextLowestDensityRow lt;gt; Integer.MaxValue AndAlso nextLowestDensityColumn lt;gt; Integer.MaxValue Then  Row = nextLowestDensityRow End If  

Полуфиксированный код

 'Lowest Density detector to find out which values have the highest priority.  Dim nextLowestDensityColumn As Integer = Integer.MaxValue  Dim nextLowestDensityRow As Integer = Integer.MaxValue   For Row = 0 To Uniques.Length - 1  For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.  If ProcessedBits(Row)(Column) = 1 AndAlso Uniques(Row).Length lt;gt; Column   1 AndAlso ProcessedBits(Row)(Column   1) = 0 Then 'if the column is processed, then skip it and process the next one.  If (Column   1) lt; nextLowestDensityColumn Then  nextLowestDensityColumn = Column   1  nextLowestDensityRow = Row  End If  End If  Next  Next   If nextLowestDensityRow lt;gt; Integer.MaxValue AndAlso nextLowestDensityColumn lt;gt; Integer.MaxValue Then  Row = nextLowestDensityRow  End If  

примеры плотности

Ответ №1:

Исправил это

 'Lowest Density detector to find out which values have the highest priority.  Dim nextLowestDensityColumn As Integer = Integer.MaxValue  Dim nextLowestDensityRow As Integer = Integer.MaxValue   For Row = 0 To Uniques.Length - 1  For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.  If ProcessedBits(Row)(Column) = 1 AndAlso Uniques(Row).Length lt;gt; Column   1 AndAlso ProcessedBits(Row)(Column   1) = 0 Then 'if the column is processed, then skip it and process the next one.  If (Column   1) lt; nextLowestDensityColumn Then  nextLowestDensityColumn = Column   1  nextLowestDensityRow = Row  End If  End If  Next  Next   If nextLowestDensityRow lt;gt; Integer.MaxValue AndAlso nextLowestDensityColumn lt;gt; Integer.MaxValue Then  Row = nextLowestDensityRow  End If