Je ne suis pas sûr si ma question post a beaucoup de sens; Cependant, je construis un tableau d'entrée pour une classe/fonction qui prend beaucoup de données entrées par l'utilisateur et qui génère un tableau numpy.Organisation et construction d'un tableau numpy pour une entrée d'équation dynamique
# I'm trying to build an input array that should include following information:
'''
* zone_id - id from db - int
* model size - int
* type of analysis - one of the following:
* type 1 - int or string
* type 2 - int or string
* type 3 - int or string
* model purposes:
* default: ONE, TWO, THREE #this is just a title of the purpose
* Custom: default + others (anywhere from 0 to 15 purposes)
* Modeling step 1: some socio economic factors #produces results 1
* Modeling step 2:
* Default: equation coefficients for retail/non retail
* Custom: equation coefficients for each extra activities as defined by
the user
* produces results 2
Example array:
def_array = (zone_id, model_size, analysis_type,
model_purpose[],
socio_economics[],
socio_coefficients[])
'''
# Numerical example:
my_arr = [np.array([ 10001, 1, 2,
[ 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' ],
[ {'retail':500, 'non_retail':300, 'school':300', 'other':900} ],
[ {'retail':500, 'non_retail':300, 'school':300', 'other':900} ],
[ {'ONE':{'retail':.5, 'non_retail':1.7, 'school':.4', 'other':4.7},
{'TWO':{'retail':.2, 'non_retail':2.5, 'school':.5', 'other':4.3},
{'THREE':{'retail':.3, 'non_retail':2.3, 'school':.6', 'other':2.2},
{'FOUR':{'retail':.4, 'non_retail':1.1, 'school':.7', 'other':1.0},
{'FIVE':{'retail':7, 'non_retail':2, 'school':3', 'other':1} ] ])
# this array will be inserted into 3 functions and together should return the following array:
arr_results = [np.array([ 10001, one_1, TWO_1, THREE_1, FOUR_1, FIVE_1, ONE_2, TWO_2, THREE_2, FOUR_2, FIVE_2],
[10002, .... ,] ])
- Quels sont/est ma meilleure option (s) dans la définition du tableau d'entrée (s)?
Êtes-vous sûr que vous pouvez construire un tel tableau numpy compliqué? Les tableaux Numpy sont excellents pour les grandes formes régulières de données du même type. Peut-être définir une classe avec des attributs spécifiques (certains d'entre eux peuvent être des tableaux numpy). – eumiro
@eumiro - cela fonctionne aussi, n'hésitez pas à poster une réponse expliquant que s'il vous plaît :) – dassouki
katrielalex a une solution lightweighter pour vous – eumiro