#๐Ÿ”’ Numpy array

34 messages ยท Page 1 of 1 (latest)

heady breach
#

is it okay to create a big numpy array inside a loop or would it be better to create it before the loop starts

charred peakBOT
#

@heady breach

Python help channel opened

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.

bold moth
#
# 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)
heady breach
#

how to do that code properly

bold moth
#

what are you trying to do

#

!code

charred peakBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

bold moth
#

please do not post screenshots of text

charred peakBOT
#

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.
bold moth
heady breach
#
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)

bold moth
#

thank you

heady breach
#

i need the copy of L array

#

to have acces on previous step

bold moth
#

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

heady breach
#

i mean

#

i need to overwrite it

#

without overwriting original

#

wait

#

other way around

#

i need to owerwrite original

#

without owerwriting old

bold moth
#

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.

heady breach
#

oh i see

#

so if i just assign it gonna work as link

bold moth
#

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

heady breach
#

OKAY THANKS

bold moth
#

YOU ARE WELCOME

charred peakBOT
#
Python help channel closed

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.