- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
Issue41827
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2020-09-21 18:49 by jeetshahj12375, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| matrix summation-Copy1.ipynb | jeetshahj12375, 2020-09-21 18:49 | |||
| Messages (6) | |||
|---|---|---|---|
| msg377268 - (view) | Author: jeet shah (jeetshahj12375) | Date: 2020-09-21 18:49 | |
See difference in output by changing array definition. |
|||
| msg377270 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2020-09-21 19:06 | |
Please provide the output you see and the output you expect. And it would be better if you could just post the code into the comment window. I, for one, cannot run your .ipynb file. |
|||
| msg377283 - (view) | Author: jeet shah (jeetshahj12375) | Date: 2020-09-21 21:03 | |
after = [[1,2],[3,4]]
rows, cols = (len(after), len(after[0]))
before = [[0]*cols]*rows
# before = [[0 for i in range(cols)] for j in range(rows)] #uncomment this array definition and comment above one... see difference in output.
print(before)
def calculation(a,b):
s = after[0][0]
for x in range(a+1):
for y in range(b+1):
s += before[x][y]
before[a][b] = after[a][b] - s
def cal2():
for x in range(len(after)):
for y in range(len(after[0])):
calculation(x,y)
before[0][0] = after[0][0]
print(before)
cal2()
#expected output: [[1, 1], [2, 0]]
|
|||
| msg377286 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2020-09-21 21:39 | |
Your example is too complex to work through in my head, but I suspect this is the issue you're seeing: https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x In any event, this is almost certainly not a bug in Python, but rather in your code. You might want to ask this question on the python-list mailing list https://mail.python.org/mailman/listinfo/python-list or on Stack Overflow, which are more appropriate venues than the bug tracker. |
|||
| msg377343 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2020-09-22 18:26 | |
See https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list. |
|||
| msg377346 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2020-09-22 19:22 | |
Thanks, Serhiy. That's a better section than I found. I'm going to close this. @jeetshahj12375: If you can show that this is a bug in python, please re-open this issue. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:35 | admin | set | github: 85993 |
| 2020-09-22 19:22:24 | eric.smith | set | status: open -> closed resolution: not a bug messages: + msg377346 stage: resolved |
| 2020-09-22 18:26:48 | serhiy.storchaka | set | status: pending -> open nosy: + serhiy.storchaka messages: + msg377343 |
| 2020-09-22 18:09:54 | eric.smith | set | status: open -> pending |
| 2020-09-21 21:39:58 | eric.smith | set | messages: + msg377286 |
| 2020-09-21 21:03:40 | jeetshahj12375 | set | messages: + msg377283 |
| 2020-09-21 19:06:11 | eric.smith | set | nosy:
+ eric.smith messages: + msg377270 |
| 2020-09-21 18:49:48 | jeetshahj12375 | create | |


