How to save a numerical search table in Python (with labels)

I have a scientific model that I run in Python that creates a lookup table as output. That is, he creates a multidimensional β€œtable”, where each dimension is a parameter in the model, and the value in each cell is the output of the model.

My question is how best to store this lookup table in Python. I run the model in a cycle of all possible combinations of parameters (using a fantastic function itertools.product), but I can’t decide what is the best way to save the outputs.

It would seem reasonable to just save the output as ndarray, but I would really like to have access to the outputs based on parameter values, and not just indexes. For example, instead of referring to values ​​as table[16][5][17][14], I prefer to access them in some way using variable names / values, for example:

table[solar_z=45, solar_a=170, type=17, reflectance=0.37]

or something like that. It would be great if I could iterate over the values ​​and return their parameter values, i.e. Detect what table[16]...matches the outputs for solar_z = 45.

Is there any reasonable way to do this in Python?

+5
source share
4 answers

? MongoDB ( Python, Pymongo) - . :

  • - (2 , ).
  • map/reduce

, MongoDB, :

{"_id":"run_unique_identifier",
 "param1":"val1",
 "param2":"val2" # etcetera
}

, :

import pymongo
data = pymongo.Connection("localhost", 27017)["mydb"]["mycollection"]
for entry in data.find(): # this will yield all results
 yield entry["param1"] # do something with param1

, MongoDB/pymongo , . , , .

+4

, python ndarray .JSON json.

+1

- numpy ndarray ( ) /.

:

solar_z_dict = {...}
solar_a_dict = {...}
...
def lookup(dataArray, solar_z, solar_a, type, reflectance):
  return dataArray[solar_z_dict[solar_z] ], solar_a_dict[solar_a], ...]

eval, , "" ":" ( ).

+1

, [16] [5] [17] [14] - /

, numpy dtype :

  dt = [('L','float64'),('T','float64'),('NMSF','float64'),('err','float64')]
  data = plb.loadtxt(argv[1],dtype=dt)

data, date['T']['L']['NMSF']

dtypes: http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html

+1
source

All Articles