Bhanu Magotra
Bhanu Magotra

Reputation: 47

Xarray latitude variable with 2 dimensions

How do I create a xarray variable "latitude" which is arranged as displayed in the image below? The variable has two dimensions : east_west(x),north_south(y). The values only change along y dimension but remain same along x dimension. The numpy latitude array needs to span from 5 to 40 at 0.1 step. enter image description here

Upvotes: 0

Views: 147

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54635

How about a one-liner?

>>> nd = (-59.9+np.arange(40)/4).reshape(40,1).repeat(40,1)
>>> nd
array([[-59.9 , -59.9 , -59.9 , ..., -59.9 , -59.9 , -59.9 ],
       [-59.65, -59.65, -59.65, ..., -59.65, -59.65, -59.65],
       [-59.4 , -59.4 , -59.4 , ..., -59.4 , -59.4 , -59.4 ],
       ...,
       [-50.65, -50.65, -50.65, ..., -50.65, -50.65, -50.65],
       [-50.4 , -50.4 , -50.4 , ..., -50.4 , -50.4 , -50.4 ],
       [-50.15, -50.15, -50.15, ..., -50.15, -50.15, -50.15]])

Upvotes: 1

Related Questions