2

numpy has .r_

which

Translates slice objects to concatenation along the first axis.

This is a simple way to build up arrays quickly. There are two use cases.

If the index expression contains comma separated arrays, then stack them along their first axis.

If the index expression contains slice notation or scalars then create a 1-D array with a range indicated by the slice notation.

I am looking for a torch equivalent, originally to answer to a comment here, but also in general.

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • Fundamentally it is just `np.concatenate` with a cute way of specifying `arange` or `linspace`. You shouldn't need to find an exact equivalent. – hpaulj May 22 '21 at 15:47
  • Also `r_` is most often used to generate a discontinuous array/list of indices. `torch` objects can be indexed with numpy arrays, can't they? In which case there's no need to find/create an equivalent. – hpaulj May 22 '21 at 16:51
  • @hpaulj "most often not" strictly means "sometimes you do", in fact I use it very often – Thomas Hilger Oct 04 '22 at 10:41

0 Answers0