0

I know how to do this if I know the number of dimensions of the array when coding. I have seen Select 'area' from a 2D array in python

I am trying to figure out how to extract a "volume" from an any dimensional array.

I know how to slice arrays. a[0: 10] I know how to use that. What I essentially want is a [lower_bound: higher_bound]. But the bounds are arrays that specify the locations in each dimension.

martineau
  • 119,623
  • 25
  • 170
  • 301
Collin
  • 1
  • 1
  • You could look at the indexing [doc](https://numpy.org/doc/stable/reference/arrays.indexing.html). TL;DR: you can use an ellipsis to denote any number of dimensions: `arr[..., 1:3]` – Felix Nov 02 '20 at 21:05

1 Answers1

0

Something like 0:2, 2:4 in the answer you linked is just a tuple of range objects. You can create such a tuple yourself using any code you want, and then do a[slice(*t)] (ref) to slice with that tuple.

hobbs
  • 223,387
  • 19
  • 210
  • 288