import numpy as np
SIZE = 96
SHIFT = -SIZE/2
D2Q4 = np.zeros((SIZE + 1, SIZE + 1, 4))
D2Q4_new = D2Q4.copy()
D2Q5 = np.zeros((SIZE + 1, SIZE + 1, 5))
D2Q5_new = D2Q4.copy()
D2Q9 = np.zeros((SIZE + 1, SIZE + 1, 9))
D2Q9_new = D2Q4.copy()
velocity_model = [D2Q4, D2Q5, D2Q9]
velocity_model_new = [D2Q4_new, D2Q5_new, D2Q9_new]
for array in velocity_model:
flag = velocity_model.index(array)
print(len(velocity_model_new[flag][0][0]))
print(len(array.copy()[0][0]))
velocity_model_new[flag] = array.copy()
#๐ Doesn't let me assign one array to another
44 messages ยท Page 1 of 1 (latest)
@novel basalt
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.
i get the following error
D2Q4_new = D2Q4.copy()
D2Q5 = np.zeros((SIZE + 1, SIZE + 1, 5))
D2Q5_new = D2Q5.copy() # Corrected here
D2Q9 = np.zeros((SIZE + 1, SIZE + 1, 9))
D2Q9_new = D2Q9.copy() # Corrected here```
You are copying the D2Q4 array to all three of them.
Change your code like that.
OOOPS
this doesn't help
import numpy as np
SIZE = 96
SHIFT = -SIZE/2
D2Q4 = np.zeros((SIZE + 1, SIZE + 1, 4))
D2Q4_new = D2Q4.copy()
D2Q5 = np.zeros((SIZE + 1, SIZE + 1, 5))
D2Q5_new = D2Q5.copy()
D2Q9 = np.zeros((SIZE + 1, SIZE + 1, 9))
D2Q9_new = D2Q9.copy()
velocity_model = [D2Q4, D2Q5, D2Q9]
velocity_model_new = [D2Q4_new, D2Q5_new, D2Q9_new]
print(id(D2Q4))
print(id(velocity_model[0]))
for array in velocity_model:
print(id(array))
flag = velocity_model.index(array)
print(len(velocity_model_new[flag][0][0]))
print(len(array.copy()[0][0]))
velocity_model_new[flag] = array.copy()
!e ```py
import numpy as np
SIZE = 96
SHIFT = -SIZE/2
D2Q4 = np.zeros((SIZE + 1, SIZE + 1, 4))
D2Q4_new = D2Q4.copy()
D2Q5 = np.zeros((SIZE + 1, SIZE + 1, 5))
D2Q5_new = D2Q5.copy()
D2Q9 = np.zeros((SIZE + 1, SIZE + 1, 9))
D2Q9_new = D2Q9.copy()
velocity_model = [D2Q4, D2Q5, D2Q9]
velocity_model_new = [D2Q4_new, D2Q5_new, D2Q9_new]
print(id(D2Q4))
print(id(velocity_model[0]))
for array in velocity_model:
print(id(array))
flag = velocity_model.index(array)
print(flag)
print(len(velocity_model_new[flag][0][0]))
print(len(array.copy()[0][0]))
velocity_model_new[flag] = array.copy()
@still fog :x: Your 3.12 eval job has completed with return code 1.
001 | 140422850182960
002 | 140422850182960
003 | 140422850182960
004 | 0
005 | 4
006 | 4
007 | 140422666139856
008 | Traceback (most recent call last):
009 | File "/home/main.py", line 18, in <module>
010 | flag = velocity_model.index(array)
011 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/NDN7CQOVDCUTY57ADN7EFXUMSU
!e ```py
import numpy as np
SIZE = 96
SHIFT = -SIZE/2
D2Q4 = np.zeros((SIZE + 1, SIZE + 1, 4))
D2Q5 = np.zeros((SIZE + 1, SIZE + 1, 5))
print(D2Q4 == D2Q5)
@still fog :x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 8, in <module>
003 | print(D2Q4 == D2Q5)
004 | ^^^^^^^^^^^^
005 | ValueError: operands could not be broadcast together with shapes (97,97,4) (97,97,5)
I don't have the slighest idea of what you are trying to do, but put it simply, that is just not how you are supposed to work with numpy in first place
in particular, creating a list of array of different shapes is a bit weird, and trying to .index() it even more so
i need to iterate through them
What for?
to not make 3 instances of a function
print(len(velocity_model_new[i][0][0]))
print(len(velocity_model[i][0][0]))
velocity_model_new[i] = velocity_model[i].copy()```
that (or enumerate) makes a lot more sense, but is still a bit weird
wait, enumerate is weird? Why?
in general it is good
for this specific case, iterating over that list in first place is already weird
yeah no, that makes even less sense to me
you're trying to plot something with shape (size, size, 9)?
i'm vectorizing it
doesn't matter
theres 3 matrixes
needed to be plotted at every step on the same figure
hmm ok, go ahead and use enumerate() then, if it works it works
!e ```py
values = ['x', 'y', 'z']
for i, val in enumerate(values):
print(i)
print(val)
@still fog :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 0
002 | x
003 | 1
004 | y
005 | 2
006 | z
forgot the range
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.