简体   繁体   中英

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?

You can use * unpacking:

l = [arr1, *arr2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM