numpy.expand_dims(a, axis)
作用:擴展數組的維度
例:
def load_pose_cords_from_strings(y_str, x_str):
"""
x_str = '[..., ..., ..., ...]' (str)
x_cords = [..., ..., ..., ...] (list)
x_cords_expanded = [[...], [...], [...], [...],....] (ndarray)
"""
y_cords = json.loads(y_str) # json.loads()把str轉成list
x_cords = json.loads(x_str)
# 在最后一個維度擴展一維,即將長度為18的list轉成shape為(18,1)的ndarray數組
y_cords_expanded = np.expand_dims(y_cords, -1)
x_cords_expanded = np.expand_dims(x_cords, -1)
return np.concatenate([y_cords_expanded, x_cords_expanded], axis=1)