5

Is there an alternative way to create a numpy array filled with a character, e.g.:

p = np.array( [' '] * 12 )

Is there a way to use np.full(...)?

0

1 Answer 1

8

Yes np.full could be used with the correct datatype (string) being mentioned with it, like so -

np.full((12), [' '],dtype=str)

You can also use np.repeat -

np.repeat([' '], 12)
Sign up to request clarification or add additional context in comments.

2 Comments

You can do it without the one-item list: np.full(12, ' ', dtype=str)
@askewchan Thanks! That works too. Being a minor change, I would keep it as it is for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.