Romain
Romain

Reputation: 145

Add numpy array to list python

Let's say I have two arrays

arr1 = np.array([1, 2, 3, 4, 5])
arr2 = np.array([[1, 2, 3], [4, 5, 6]])

I want to create a list which contains each sequence of arr1 and arr2. I do that with

l = [arr1, arr2[0], arr2[1]]

But the length of arr2 can change, how can I create a list with loop for ? Or another way ?

Upvotes: 2

Views: 133

Answers (1)

a_guest
a_guest

Reputation: 36249

You can use * unpacking:

l = [arr1, *arr2]

Upvotes: 5

Related Questions