[英]compare 2D array with 1D array
how I can compare each row of 2D array with 1d array in order to insert 1D array if it is not found in 2D array if my 2d array is like {{3,7,9},{1y ,8,6}} and my 1d array for example {3,7,9},how I can know if it's already there ,my code below insert 1d array at a time to 2d array ,I tried to use .equal but it doesn't work 如果我的2d数组像{{3,7,9},{1y,8,6}}时如何将2D数组的每一行与1d数组进行比较以插入1D数组(如果在2D数组中找不到)我的1d数组例如{3,7,9},我怎么知道它是否已经存在,我下面的代码一次将1d数组插入2d数组,我尝试使用.equal,但它不起作用
Private Sub Add_Item_Array_2D2(ByRef Array_2D As Double(,), ByVal d As Integer,
ByVal Items As Double())
Dim tmp_array(Array_2D.GetUpperBound(0) + d, Array_2D.GetUpperBound(d)) As Double
For n As Integer = 0 To Array_2D.GetUpperBound(0)
For m = 0 To Array_2D.GetUpperBound(1)
Dim pp = (Array_2D(n, m)).Equals(Items)
If pp = False Then
For x As Integer = 0 To Array_2D.GetUpperBound(0)
For k = 0 To Array_2D.GetUpperBound(1)
tmp_array(x, k) = Array_2D(x, k)
Next
Next
For j = 0 To Items.Count - 1
tmp_array(tmp_array.GetUpperBound(0), j) = Items(j)
Next
Array_2D = tmp_array
End If
Next
Next
End Sub
How to find out whether a row in your 2D array equals your 1D array: 如何确定2D数组中的行是否等于1D数组:
Compare bounds. If the column count of your 2D array is unequal
to the length of your 1D array, throw an error.
Loop through the rows of the 2D array:
If, for all column indexes, 2D(row, column) = 1D(column):
return Success
return Failure
Translating this algorithm to VB.NET is left as an exercise. 剩下的练习是将此算法转换为VB.NET。 Hint: For the
for all
part, Enumerable.Range
and Enumerable.All
might be helpful. 提示:对于
for all
, Enumerable.Range
和Enumerable.All
可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.