我对以下代码有疑问:
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)
然后mat1
和mat2
被修改:
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访问项目,不是吗?
答案 0 :(得分: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