1

Is there an effective way to assign a Numpy array to a set of variables, each variable being assigned to the subsequent array element?

Pseudocode:

[a,b,c,d] = A 

where A is a 2x2 matrix.

1 Answer 1

3
In [13]: A = np.arange(4).reshape(2, 2)

In [14]: A
Out[14]:
array([[0, 1],
       [2, 3]])

In [16]: A.ravel()
Out[16]: array([0, 1, 2, 3])

In [17]: a, b, c, d = A.ravel()

In [18]: a, b, c ,d
Out[18]: (0, 1, 2, 3)
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.