| 1 | initial version |
Concerning your
motivation: sagematrix,it seems, are not "hashable" and cannot be used as keys in lists to do groupby/countby
I'd like to make a comment. Matrices in sage are, by default, mutable and hence (just like lists in python) not hashable. You can a matrix to be immutable, and if its entries are hashable, the matrix itself is also hashable.
sage: A=random_matrix(ZZ,1,5)
sage: hash(A)
TypeError: mutable matrices are unhashable
sage: A.set_immutable()
sage: hash(A)
-4
If you're OK with your matrices being immutable, this can save you having to copy the entries into tuples.
| 2 | No.2 Revision |
Concerning your
motivation: sagematrix,it seems, are not "hashable" and cannot be used as keys in lists to do groupby/countby
I'd like to make a comment. Matrices in sage are, by default, mutable and hence (just like lists in python) not hashable. You can set a matrix to be immutable, and if its entries are hashable, the matrix itself is will also be hashable.
sage: A=random_matrix(ZZ,1,5)
sage: hash(A)
TypeError: mutable matrices are unhashable
sage: A.set_immutable()
sage: hash(A)
-4
If you're OK with your matrices being immutable, this can save you having to copy the entries into tuples.
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.