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.]

1 Answers1

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

user8408080
  • 2,428
  • 1
  • 10
  • 19