If you like pythonic list comprehension and one-liner:
b =7 x= [-3.14, 0, 3.14] x2 = np.array([int((2**b - 1) * xi / np.max(np.abs(x))) if xi > 0 else int(-2**b * xi / np.max(np.abs(x))) for xi in x])