Skip to content

How to "slice" a single dimension of an array? #900

Answered by philipc2
mkavulich asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @mkavulich

To use our plotting routines, you want your data to only have a n_edge, n_face or n_node dimension, with no leading dimensions (i.e. a 1D slide of unstructured data) like you mentioned.

The typically way to achieve this would be to use isel() to select a slice from the other dimensions. This would look like the following:

# same as uxds["surface_pressure"][0]
uxds["surface_pressure"].isel(Time=0)

# same as uxds["theta"][0, :, 0]
uxds["theta"].isel(Time=0, nVertLevels=0)

The reason you are getting strange results is that when you are indexing the array, you have separate brackets (i.e. [][][]) instead of doing a single multidimensional index when you use the colon (which is …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mkavulich
Comment options

Answer selected by mkavulich
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants