#๐ Numpy array
34 messages ยท Page 1 of 1 (latest)
@heady breach
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.
one would need more information to answer that. but you should pretty much never pre-allocate an array and iteratively populate it
# this is wrong
arr = np.zeros((5, 3))
for i in range(5):
for j in range(3):
arr[i, j] = some_func(i, j)
how to do that code properly
please do not post screenshots of text
Hey @heady breach!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
please read this
def modify_Tm(x, y, m):
L_old = L
if m == 0:
flag1 = find_nearest_node(x-1)
flag2 = Tm(flag1, y, m)
flag3 = Tm_eq(flag1, y)
elif m == 1:
flag1 = find_nearest_node(y+1)
flag2 = Tm(x, flag1, m)
flag3 = Tm_eq(x, flag1)
elif m == 2:
flag1 = find_nearest_node(x+1)
flag2 = Tm(flag1, y, m)
flag3 = Tm_eq(flag1, y)
elif m == 3:
flag1 = find_nearest_node(y - 1)
flag2 = Tm(x, flag1, m)
flag3 = Tm_eq(x, flag1)
L[x][y][m] = flag2 - W * (flag2 - flag3)
thank you
assignment never copies data in Python, so L_old = L will not create a copy
you have to do L_old = L.copy() for that
i mean
i need to overwrite it
without overwriting original
wait
other way around
i need to owerwrite original
without owerwriting old
L_old and L refer to the exact same object, so any changes made to L will appear in L_old, because they are the same thing.
assignments just assign names to things. they don't create or copy data.
another thing is that L[x][y][m] should be L[x, y, m]
arrays are one object, no matter how many dimensions they have. whereas nested lists are multiple objects. @heady breach
OKAY THANKS
YOU ARE WELCOME
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.