New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing Matrix row/col ranges produces incorrect results #26588
Comments
Can you elaborate on which one of these you think is the incorrect result? Also, it would be nice if you use the code font for the code snippets. You can use single backticks (`) for single lines, and triple backticks (```) for multiline snippets. As far as I agree that the output of |
I did a little investigating, and the behavior is arising from this part of the code: sympy/sympy/matrices/repmatrix.py Lines 966 to 978 in b412fa4
Here, if I'm not sure if this is the intended/desired behavior or not. If it is, then it should definitely be documented somewhere. |
This is just how slicing in Python works: In [58]: l = [1,2,3,4]
In [59]: l[:10]
Out[59]: [1, 2, 3, 4] |
I don't think that we should change this. It is reasonable and robust that matrix should follow how Python slicing just works, and changing that gives further confusion that benefit. Also, in general programming advice, you should avoid writing code like |
Initialization
from sympy import Matrix, shape
M = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(M)
Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
pprint(shape(M))
(3, 3)
Accessing ranges produces incorrect results
print(M[0:1,0:1])
Matrix([[1]])
print(M[0:2,0:2])
Matrix([[1, 2], [4, 5]])
print(M[0:3,0:3])
Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(M[0:9,0:9])
Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
The text was updated successfully, but these errors were encountered: