[Python] Cupy throwing a unhashable type: 'ndarray' when appending nested tuples to a set

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    For a project we are trying to convert numpy code to cupy code for the speedup but we are getting this error:

    TypeError: unhashable type: 'ndarray'


    When we run

    import cupy as cp
    newMat = cp.array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.], [ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., -1.]])
    newMatSet = set()
    newMatSet.add(tuple(tuple(row) for row in sortBis(newMat)))


    With sortBis simply reordering the matrix:

    def sortBis(mat: np.ndarray):
    colInds = cp.lexsort(mat[:, 1:])
    mat[:, 1:] = mat[:, 1:][:, colInds]
    return mat


    It is my understanding that a nested tuple should be hashable, and this code works perfectly find with numpy. Does anyone know of a fix?

    Continue reading...

Compartilhe esta Página