def merge(clusts, centroids, mats, maps, i):
    minDist = -1
    index = -1
    cent = centroids[i]
    for j in range(0, len(centroids)):
        distance = dist(cent,centroids[j])
        if (i == j):
            continue
        elif (minDist == -1) or distance < minDist:
            minDist = distance
            index = j
    for j in range(0, len(clusts[i])):
        if not isinstance(clusts[index],list):
            clusts[index].tolist()
        clusts[index].append(clusts[i][j])
    
    newMat = []
    newMap = {}
    st.redoMatrix(clusts, index, newMat, newMap)
    mats[index] = np.array(newMat)
    maps[index] = newMap
    newCent = findCenter(mats[index])
    centroids[index] = newCent

    maps.pop(i)
    mats.pop(i)
    centroids.pop(i)    
    clusts.pop(i)
def merge(clusts, centroids, mats, maps, i):
    minDist = -1
    index = -1
    cent = centroids[i]
    for j in range(0, len(centroids)):
        distance = u.dist(cent, centroids[j])
        if (i == j):
            continue
        elif (minDist == -1) or distance < minDist:
            minDist = distance
            index = j
    for j in range(0, len(clusts[i])):
        if not isinstance(clusts[index], list):
            clusts[index] = clusts[index].tolist()
        clusts[index].append(clusts[i][j])

    newMat = []
    newMap = {}
    st.redoMatrix(clusts, index, newMat, newMap)
    mats[index] = np.array(newMat)
    maps[index] = newMap
    newCent = u.findCenter(mats[index])
    centroids[index] = newCent

    maps.pop(i)
    mats.pop(i)
    centroids.pop(i)
    clusts.pop(i)
def dissolve(clusts, centroids, mats, maps, i):
    trans = mats[i].transpose()
    cl.__init__(trans, clusts[i], maps[i])
    num = len(clusts[i])/8+1
    results = cl.kMeans(num, 20)

    pClusts = results[0]
    pCents = results[1]
    clusts.pop(i)
    centroids.pop(i)
    mats.pop(i)
    maps.pop(i)

    for j in range(0, len(pClusts)):
        clusts.append(pClusts[j])
        centroids.append(pCents[j])
        newMat = []
        newMap = {}
        st.redoMatrix(clusts,len(clusts)-1,newMat, newMap)
        mats.append(newMat)
        maps.append(newMap)
def dissolve(clusts, centroids, mats, maps, i):
    trans = mats[i].transpose()
    cl.__init__(trans, clusts[i], maps[i])
    num = len(clusts[i]) / 8 + 1
    results = cl.kMeans(num, 20)

    pClusts = results[0]
    pCents = results[1]
    clusts.pop(i)
    centroids.pop(i)
    mats.pop(i)
    maps.pop(i)

    for j in range(0, len(pClusts)):
        clusts.append(pClusts[j])
        centroids.append(pCents[j])
        newMat = []
        newMap = {}
        st.redoMatrix(clusts, len(clusts) - 1, newMat, newMap)
        mats.append(newMat)
        maps.append(newMap)