1

I want to create a meshgrid and I only have one 2-dimensional array.

I want to create this:

a = np.array([1,2])
b = np.array([3,4])
mesh = np.array(np.meshgrid(a, b))
## mesh = 
## array([[[1, 2],
##    [1, 2]],
##
##   [[3, 3],
##    [4, 4]]])

but the input is one array containing a and b, like this:

ab = np.array([[1,2],[3,4]])
mesh = np.array(np.meshgrid(ab))
## mesh = 
## array([[[1, 2],
##    [1, 2]],
##
##   [[3, 3],
##    [4, 4]]])

Is their a way to archive that even with 3 or 4 arrays packed in one big one like this:

abcd = np.array([[1,2],[3,4],[5,6],[7,8]])

1 Answer 1

3

Yes, we can unpack abcd and pass to messgrid:

mesh = np.array(np.meshgrid(*abcd))
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.