1

我对以下代码有疑问:

def getJenksBreaks( dataList, numClass ):

dataList.sort()

mat1 = []
for i in range(0,len(dataList)+1):
    temp = []
    for j in range(0,numClass+1):
        temp.append(0)
    mat1.append(temp)

mat1例如看起来像这样

0, 0, 0, 0, 0, 0

0, 0, 0, 0, 0, 0

0, 0, 0, 0, 0, 0

0, 0, 0, 0, 0, 0

之后,mat2创建:

mat2 = []
for i in range(0,len(dataList)+1):
    temp = []
    for j in range(0,numClass+1):
        temp.append(0)
mat2.append(temp)

然后mat1mat2被修改:

for i in range(1,numClass+1):
    mat1[1][i] = 1
    mat2[1][i] = 0
    for j in range(2,len(dataList)+1):
        mat2[j][i] = float('inf')

当我看到这一行时:

 mat1[1][i] = 1

在我看来,XY 位置的项目已更改。

我想将此代码移植到 VB6,但我看不到任何方法可以在 VB6 中反映这种行为。集合无法做到这一点,我的意思是使用 X 和 Y 访问项目,是吗?

4

1 回答 1

0

好吧,我创建了自己的类来处理这个问题。如果有人有更好的主意,请告诉我。

Option Explicit

Private m_XCount&
Private m_YCount&
Private m() As Variant

Public Sub Add(ByRef u() As Variant)

    If UBound(u) > m_XCount Then
        m_XCount = UBound(u)
    End If

    m_YCount = m_YCount + 1

    ReDim Preserve m(0 To m_XCount, 0 To m_YCount)

    Dim l&
    For l = 0 To UBound(u)
        m(m_XCount + l, m_YCount) = u(l + 1)
    Next l

    m_YCount = m_YCount + 1

End Sub

Private Sub Class_Initialize()

    ReDim m(0, 0)

End Sub
Public Property Get Value(ByVal uX As Long, ByVal uY As Long) As Variant

    Value = m(uX, uY)

End Property
Public Property Let Value(ByVal uX As Long, ByVal uY As Long, ByVal uValue)

    m(uX, uY) = uValue

End Property
于 2013-10-17T20:01:07.223 回答