-1

I wanted to create a numpy array with same number of digits in each element. Suppose: User_001, User_002,....,User_123 How can I do this? I tried as follows: a1 = np.array([f'User_{i}' for i in range(124)]) But it gives me: User_1, User_2, User_3......,User_123 which I do not want. Any help?

1

2 Answers 2

2

here you go

import numpy as np

np.array([f'User_{str(i).zfill(3)}' for i in range(124)])
Sign up to request clarification or add additional context in comments.

Comments

1

Not the most elegant solutions, but should do well.

a1 = np.array([f'User_{str(i).rjust(3, str(0))}' for i in range(124)])
# or
a1 = np.array([f'User_{str(i).zfill(3)}' for i in range(124)])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.