0

I have this piece of code regarding the meshgrid function that I want to modify it's output:

x_list = list(range(5))
y_list = list(range(2))
X, Y = meshgrid(x_list, y_list)

which prints out:

X
array([[0, 1, 2, 3, 4],
       [0, 1, 2, 3, 4]])

and

    Y = array([[0, 0, 0, 0, 0],
               [1, 1, 1, 1, 1]])

How can I modify my output to produce

    X = array([0,0,0,0,0],
              [1,1,1,1,1]

and Y = array([0,1], [0,1], [0,1], [0,1], [0,1]]

instead? What I have in mind is something like this making X basically representing the x_axis values and Y the Y-axis values:

    03 13 23 33 43
    02 12 22 32 42
    01 11 21 31 41
    00 10 20 30 40

in the end I am doing something wrong I know it but I can't figure how to change the code in meshgrid in order to get me a normal x-y plane.

Mahmoud Ayman
  • 197
  • 1
  • 13

1 Answers1

1
size= 4
X = np.array([np.zeros(size), np.ones(size)])
Y = X.copy().T

will get the output you want. But if you're using meshgrid, aren't you feeding functions that expect the format meshgrid produces?

cphlewis
  • 15,759
  • 4
  • 46
  • 55
  • Now I want that output to be from meshgrid function coz I don't want to create X by myself but would rather want meshgrid function to output it for me with a suitable input to get the output you wrote me. – Mahmoud Ayman May 04 '15 at 23:08
  • It would be bad practice to change the behavior of a widely used function like `meshgrid`. If you want the output you asked for, this is a short way to get it. – cphlewis May 04 '15 at 23:25