-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
A replacement for np.matrix #13835
Copy link
Copy link
Open
Description
As touched upon in in #13797
matrix was a collection of behaviors, some good and some bad:
.Iand.Hattributes. These were handy.*meansmatmul- not inherently bad, but perhaps surprising, and certainly less necessary in the presence of@. I think there might still be some value in allowing "multiply (*)" on matrix objects to mean what@does on array objects - it allows them to be dropped into some equations in place of scalars- Everything is always exactly 2d. This was the cause of almost all the pain within numpy when handling subclasses - it broke liskov substitution
I think there might be a good use case for a matrix with some subset of the following rules:
- Construction fails if the input array is not
ndim >= 2 - Helpers for (stacks of) row and column vectors:
matrix.rowvec(rows) == matrix(rows[..., None, :])matrix.colvec(cols) == matrix(cols[..., :, None])
- Simpler indexing rules:
- Shape of the returned array always matches
ndarray m[..., i, j], whereiandjindex and preserve the last two dimensions, returns amatrixobject. Any type of indexing that discards the last two dimensions downcasts toarray
- Shape of the returned array always matches
.Tmeanslinalg.transpose(self),.Hmeans.T.conj().Ieither meanslinalg.inverse(self)or perhaps an object with__mul__ = linalg.solve
Such as class would not be compatible with np.matrix, but it might be a good candidate for a new numpy/matrix package.
Reactions are currently unavailable