pynbody.util.indexing_tricks.intersect_slices#
- pynbody.util.indexing_tricks.intersect_slices(s1, s2, array_length=None)[source]#
Given two python slices s1 and s2, return a slice that picks out all members of s1 and s2.
That is, if d is an array, then
d[intersect_slices(s1,s2,len(d))]
returns all elements ofd
that are in bothd[s1]
andd[s2]
.Note that it may not be possible to do this without information on the length of the array referred to, hence all slices with end-relative indexes are first converted into begin-relative indexes. The slice returned may be specific to the length specified.
If the slices are mutually exclusive, a zero-length slice is returned.
- Parameters:
s1 (slice) – The first slice
s2 (slice) – The second slice
array_length (int, optional) – The length of the array to which the slices refer. If not specified, the slices must have positive start and stop.
- Returns:
A slice that picks out all elements of s1 and s2, as described above.
- Return type:
slice