code: def bounds_tree(bounds):
      
      bounds = np.asanyarray(copy.deepcopy(bounds), dtype=np.float64)
      if len(bounds.shape) != 2:
          raise ValueError('Bounds must be (n,dimension*2)!')
  
      dimension = bounds.shape[1]
      if (dimension % 2) != 0:
          raise ValueError('Bounds must be (n,dimension*2)!')
      dimension = int(dimension / 2)
  
      import rtree
      # some versions of rtree screw up indexes on stream loading
      # do a test here so we know if we are free to use stream loading
      # or if we have to do a loop to insert things which is 5x slower
      rtree_test = rtree.index.Index([(1564, [0, 0, 0, 10, 10, 10], None)],
                                     properties=rtree.index.Property(dimension=3))
      rtree_stream_ok = next(rtree_test.intersection([1, 1, 1, 2, 2, 2])) == 1564
  
      properties = rtree.index.Property(dimension=dimension)
      if rtree_stream_ok:
          # stream load was verified working on inport above
          tree = rtree.index.Index(zip(np.arange(len(bounds)),
                                       bounds,
                                       [None] * len(bounds)),
                                   properties=properties)
      else:
          # in some rtree versions stream loading goofs the index
          log.warning('rtree stream loading broken! Try upgrading rtree!')
          tree = rtree.index.Index(properties=properties)
          for i, b in enumerate(bounds):
              tree.insert(i, b)
      return tree
docs: Given a set of axis aligned bounds, create an r-tree for broad- phase
      collision detection
  
      Parameters
      ---------
      bounds: (n, dimension*2) list of non- interleaved bounds
               for a 2D bounds tree:
               [(minx, miny, maxx, maxy), ...]
  
      Returns
      ---------
      tree: Rtree object