Cupy werfen einen unveränderlichen Typ: 'nDarray', wenn sie verschachtelte Tupel an einen Satz anhängen
Posted: 18 Aug 2025, 22:44
Für ein Projekt versuchen wir, Numpy-Code für die Beschleunigung in den Cupy-Code umzuwandeln, aber wir erhalten diesen Fehler: < /p>
TypeError: unhashable type: 'ndarray'
< /code>
Wenn wir < /p>
ausführenimport 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)))
< /code>
Mit Sortbis ordnen einfach die Matrix neu: < /p>
def sortBis(mat: cp.ndarray):
colInds = cp.lexsort(mat[:, 1:])
mat[:, 1:] = mat[:, 1:][:, colInds]
return mat
< /code>
Ich verstehe, dass ein verschachteltes Tupel hashabel sein sollte, und dieser Code funktioniert mit Numpy vollkommen in Ordnung. Kennt jemand einen Fix?
TypeError: unhashable type: 'ndarray'
< /code>
Wenn wir < /p>
ausführenimport 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)))
< /code>
Mit Sortbis ordnen einfach die Matrix neu: < /p>
def sortBis(mat: cp.ndarray):
colInds = cp.lexsort(mat[:, 1:])
mat[:, 1:] = mat[:, 1:][:, colInds]
return mat
< /code>
Ich verstehe, dass ein verschachteltes Tupel hashabel sein sollte, und dieser Code funktioniert mit Numpy vollkommen in Ordnung. Kennt jemand einen Fix?