1

What is the best way to create a numpy array with the following data:

my_array = [[1, 2, 3], [1, 2, 3], ... , [1, 2 ,3]]

with [1, 2, 3] repeated about 100 times.

I have made some test with tile, repat, etc. but result is always [1, 2, 3, 1 ,2, 3, 1, 2, etc.]

0

1 Answer 1

2

Use list comprehension:

my_array = np.array([[1,2,3] for i in range(100)])

This writes [1,2,3] a hundred times in a list and converts it to a numpy array

Sign up to request clarification or add additional context in comments.

1 Comment

Works fine, thx

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.