def toscalar(arg): arg = npp.checksize(arg, 1) r = np.ndim(arg) if r == 1: arg = arg[0] elif r == 2: arg = arg[0, 0] return arg