2

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 ?

1
  • This smells like an XY-problem. You should ask what you REALLY want. Commented Jan 25, 2022 at 12:14

1 Answer 1

5

You can use * unpacking:

l = [arr1, *arr2]
Sign up to request clarification or add additional context in comments.

Comments

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.