hepi.util
Collection of utility functions for the hepi
package.
Module Contents
Classes
Functions
|
Convert a list of objects into a dictionary of lists. |
|
Convert a dict of list`s to a `pandas.DataFrame. |
|
Creates a sha256 hash from the objects string representation. |
|
Converts a LHAPDF name to the sets id. |
|
- hepi.util.LD2DL(l, actual_dict=False)[source]
Convert a list of objects into a dictionary of lists.
The values of each object are first converted to a dict through the __dict__ attribute.
- Parameters:
l (List) – list of objects.
actual_dict (bool) – objects are already dicts
- Returns:
dictionary of numpy arrays.
- Return type:
dict
Examples
>>> class Param: ... def __init__(self,a,b,c): ... self.a = a ... self.b = b ... self.c = c >>> LD2DL([ Param(1,2,3), Param(4,5,6) , Param(7,8,9) ]) {'a': array([1, 4, 7]), 'b': array([2, 5, 8]), 'c': array([3, 6, 9])}
- hepi.util.DL2DF(ld)[source]
Convert a dict of list`s to a `pandas.DataFrame.
- Parameters:
ld (dict) –
- Return type:
pandas.DataFrame
- hepi.util.namehash(n)[source]
Creates a sha256 hash from the objects string representation.
- Parameters:
n (any) – object.
- Returns:
sha256 of object.
- Return type:
str
Examples
>>> p = {'a':1,'b':2} >>> str(p) "{'a': 1, 'b': 2}" >>> namehash(str(p)) '3dffaea891e5dbadb390da33bad65f509dd667779330e2720df8165a253462b8' >>> namehash(p) '3dffaea891e5dbadb390da33bad65f509dd667779330e2720df8165a253462b8'