def normalize_attr_values(a: Any) -> np.ndarray:
"""
Take all kinds of input values and validate/normalize them.
Args:
a List, tuple, np.matrix, np.ndarray or sparse matrix
Elements can be strings, numbers or bools
Returns
a_normalized An np.ndarray with elements either float64 or unicode string objects
Remarks:
This method should be used to prepare the values to be stored in the HDF5 file. You should not
return the values to the caller; for that, use materialize_attr_values()
"""
scalar = False
if np.isscalar(a):
a = np.array([a])
scalar = True
arr = normalize_attr_array(a)
if np.issubdtype(arr.dtype, np.integer) or np.issubdtype(arr.dtype, np.floating):
pass # We allow all these types
elif np.issubdtype(arr.dtype, np.character) or np.issubdtype(arr.dtype, np.object_):
arr = normalize_attr_strings(arr)
elif np.issubdtype(arr.dtype, np.bool_):
arr = arr.astype('ubyte')
if scalar:
return arr[0]
else:
return arr
评论列表
文章目录