#3 Joker
Ahoj, tak jsem na to nepřišel. Posílám ukázku kódu. Udělal jsem si simulaci v1, kde mi to nevychází. V simulaci v2, je výsledek, který očekávám ve ve v1. Díky za pomoc.
Kód:
global_variables.py
glstStructures = ['2;3;1']
glstProcessedStructure = []
calc.py
from global_variables import *
import random
# transfer to list
def model_code_to_list(structure):
core_list = []
y_list = []
z_list = [None, None, None, None]
x_val_num = 0
for x_val in structure.split(";"):
for y in (x_val):
y_list = [z_list for n in range(int(y))] #
#
core_list.append(y_list) # navazu na vrstvy
x_val_num = x_val_num + 1 # pocitam vrstvy od 0
return core_list
def PrepareStructure(model):
for structure in model:
vlstProcessedStructure = model_code_to_list(structure)
return vlstProcessedStructure
#
def set_Z0(model:list, x:int, y:int):
model[x][y][0] = random.random()
#
def get_x_count(model:list):
res = len(model)
return res
#
def get_y_count(model:list, y:int):
res = len(model[y])
return res
#
def init_Z0(model):
for x in range(get_x_count(model)):
for y in range(get_y_count(model, x)):
set_Z0(model,x,y)
#
def GetCalc():
print('v1')
global glstStructures
global glstProcessedStructure
glstProcessedStructure = PrepareStructure(glstStructures)
print(glstStructures)
print(glstProcessedStructure)
init_Z0(glstProcessedStructure)
print(glstProcessedStructure)
#
print('v2')
lstTest = [[[None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None]]]
print(lstTest)
init_Z0(lstTest)
print(lstTest)
Výstup:
v1
['2;3;1']
[[[None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None]]]
[[[0.5528923455878277, None, None, None], [0.5528923455878277, None, None, None]], [[0.5528923455878277, None, None, None], [0.5528923455878277, None, None, None], [0.5528923455878277, None, None, None]], [[0.5528923455878277, None, None, None]]]
v2
[[[None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None]]]
[[[0.2211728906012852, None, None, None], [0.5469049609999701, None, None, None]], [[0.4679316891134424, None, None, None], [0.31030164075610256, None, None, None], [0.18368361201238603, None, None, None]], [[0.05110759583922786, None, None, None]]]