# [Numpy-discussion] Slicing without a priori knowledge of dimension

Matthew Czesarski matthew.czesarski@gmail....
Wed Aug 6 08:02:10 CDT 2008

```Dear list.

I've got a feeling that what I'm trying to do *should* be easy but at the
moment I can't find a non-brute-force method.

I'm working with quite a high-rank matrix; 7 dimensions filled with chi**2
values. It's form is something like this:

chi2 = numpy.ones((3,4,5,6,7,8,9))

What I need to do is slice out certain 2 dimensional grids that I then want
to plot for confidence estimation; make a nice graph. This is fine: as easy
as it gets if the 2 dimensions are known. E.g. for the 2nd and 5th axes, one
could hardcode something like this:

subChi2 = chi2[ ia, ib, :, id, ie, :, ig ]

The difficulty is that the user is to state which plane (s)he wants to slice
out and we can't code the above. The function itself has to convert 2 rank
numbers into an expression for a slice and I can't currently figure out how
to do that. There are a huge number of options (well, there are 7*6=42). If
one could just manually write a colon into a tuple like (2,2,:,2,2,:,2) or
something even like 2,2,0:len(2ndDim),2,2,0:len(5thDim),2, things would be
fine. But that doesn't seem to be an option. An alternative would be to set
up 2 loops and incrementally read out the individual elements of the slice
to a new numpy.zeros ( ( len(2ndDim), len(5thDim) ) ), but again we seem to
be diverging from elegance.

There must be something that I'm missing. Could somebody have a pointer as
to what it is?

Thanks in advance,
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080806/ed76a932/attachment.html
```

More information about the Numpy-discussion mailing list