#๐ simple 2d array help
6 messages ยท Page 1 of 1 (latest)
@somber bridge
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
As in a list[list[int]] or a numpy array?
For a list of lists of ints, a for loop works fine: ```py
x = [[1,2,3],[4,5,6],[7,8,9]]
for row in x:
... row[1] += 1
...
print(x)
[[1, 3, 3], [4, 6, 6], [7, 9, 9]]
For numpy, [dimensional indexing](https://numpy.org/doc/2.1/user/basics.indexing.html#dimensional-indexing-tools) plus [broadcasting](https://numpy.org/doc/2.1/user/basics.broadcasting.html#broadcasting) ```py
>>> x = np.arange(1, 10).reshape((3,3))
>>> print(x)
[[1 2 3]
[4 5 6]
[7 8 9]]
>>> x[:, 1] += 1
>>> print(x)
[[1 3 3]
[4 6 6]
[7 9 9]]
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.