MCPcopy Create free account
hub / github.com/PythonOT/POT / list_to_array

Function list_to_array

ot/utils.py:59–83  ·  view source on GitHub ↗

r"""Convert a list if in numpy format

(*lst, nx=None)

Source from the content-addressed store, hash-verified

57
58
59def list_to_array(*lst, nx=None):
60 r"""Convert a list if in numpy format"""
61 lst_not_empty = [a for a in lst if len(a) > 0 and not isinstance(a, list)]
62 if nx is None: # find backend
63 if len(lst_not_empty) == 0:
64 type_as = np.zeros(0)
65 nx = get_backend(type_as)
66 else:
67 nx = get_backend(*lst_not_empty)
68 type_as = lst_not_empty[0]
69 else:
70 if len(lst_not_empty) == 0:
71 type_as = None
72 else:
73 type_as = lst_not_empty[0]
74 if len(lst) > 1:
75 return [
76 nx.from_numpy(np.array(a), type_as=type_as) if isinstance(a, list) else a
77 for a in lst
78 ]
79 else:
80 if isinstance(lst[0], list):
81 return nx.from_numpy(np.array(lst[0]), type_as=type_as)
82 else:
83 return lst[0]
84
85
86def proj_simplex(v, z=1):

Calls 3

get_backendFunction · 0.85
from_numpyMethod · 0.80
zerosMethod · 0.45

Tested by

no test coverage detected