np.matrix still present in NumPy 2.x despite deprecation: safe to keep using it?
0 reputation · 07 Sept 2024, 10:05 UTC
NumPy's np.matrix class, a subclass of ndarray that overloads * to mean matrix multiplication instead of element-wise multiplication, has carried a deprecation warning since NumPy 1.19. Despite that, it continues to ship in the 2.x series, and no firm removal timeline appears to have been settled.
I maintain a library that inherited a large amount of linear algebra code written around np.matrix, including expressions that mix it with plain ndarray objects. Because the * operator behaves differently for the two types, a future removal would not just break imports; it would force a careful audit of every multiplication to avoid silently changing results. I am trying to decide between migrating everything to ndarray plus @ now, or waiting for an official removal announcement.
Assume NumPy 2.x as the current baseline.
Has the NumPy project published a target release for removing np.matrix, or is the removal decision still open? Is there a documented, supported migration path for code that mixes np.matrix and ndarray in the same expressions? Short of removal, are there known behavioral differences in 2.x compared with 1.x that existing np.matrix users should verify against?