.. _op_ai_onnx_Slice: Slice ===== - **Domain**: ``ai.onnx`` - **Since version**: 13 Produces a slice of the input tensor along multiple axes. **Inputs** - **data** (*T*): Tensor of data to extract slices from. - **starts** (*Tind*): 1-D tensor of starting indices of corresponding axis in ``axes`` - **ends** (*Tind*): 1-D tensor of ending indices (exclusive) of corresponding axis in ``axes`` - **axes** (*Tind*): 1-D tensor of axes that ``starts`` and ``ends`` apply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data). Behavior is undefined if an axis is repeated. - **steps** (*Tind*): 1-D tensor of slice step of corresponding axis in ``axes``. Negative value means slicing backward. 'steps' cannot be 0. Defaults to 1s. **Outputs** - **output** (*T*): Sliced data tensor. **Type Constraints** - **T**: Constrain input and output types to all tensor types. Allowed types: tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8). - **Tind**: Constrain indices to integer types Allowed types: tensor(int32), tensor(int64). Examples -------- **test_cc_shape_inference_slice_symbolic_end** .. code-block:: text Node: Slice(X, starts, ends, axes) -> (sliced) .. code-block:: text Inputs: X: shape=(2, 3, 4), dtype=float32 [[[ 1., 2., 3., 4.], [ 5., 6., 7., 8.], [ 9., 10., 11., 12.]], [[13., 14., 15., 16.], [17., 18., 19., 20.], [21., 22., 23., 24.]]] Outputs: sliced: shape=(2, 3, 3), dtype=float32 [[[ 1., 2., 3.], [ 5., 6., 7.], [ 9., 10., 11.]], [[13., 14., 15.], [17., 18., 19.], [21., 22., 23.]]] **test_cc_slice** .. code-block:: text Node: Slice(data, starts, ends, axes, steps) -> (output) .. code-block:: text Inputs: data: shape=(20, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] starts: shape=(2,), dtype=int64 [0, 0] ends: shape=(2,), dtype=int64 [ 3, 10] axes: shape=(2,), dtype=int64 [0, 1] steps: shape=(2,), dtype=int64 [1, 1] Outputs: output: shape=(3, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]]] **test_cc_slice_axes_steps** .. code-block:: text Node: Slice(data, starts, ends, axes, steps) -> (output) .. code-block:: text Inputs: data: shape=(2, 4), dtype=float32 [[1., 2., 3., 4.], [5., 6., 7., 8.]] starts: shape=(2,), dtype=int64 [1, 0] ends: shape=(2,), dtype=int64 [2, 3] axes: shape=(2,), dtype=int64 [0, 1] steps: shape=(2,), dtype=int64 [1, 2] Outputs: output: shape=(1, 2), dtype=float32 [[5., 7.]] **test_cc_slice_default_axes_steps** .. code-block:: text Node: Slice(data, starts, ends) -> (output) .. code-block:: text Inputs: data: shape=(2, 4), dtype=float32 [[1., 2., 3., 4.], [5., 6., 7., 8.]] starts: shape=(2,), dtype=int64 [0, 1] ends: shape=(2,), dtype=int64 [ -1, 1000] Outputs: output: shape=(1, 3), dtype=float32 [[2., 3., 4.]] **test_cc_slice_default_steps** .. code-block:: text Node: Slice(data, starts, ends, axes) -> (output) .. code-block:: text Inputs: data: shape=(20, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] starts: shape=(3,), dtype=int64 [0, 0, 3] ends: shape=(3,), dtype=int64 [20, 10, 4] axes: shape=(3,), dtype=int64 [0, 1, 2] Outputs: output: shape=(20, 10, 1), dtype=float32 [[[ 3.], [ 8.], [ 13.], ..., [ 38.], [ 43.], [ 48.]], [[ 53.], [ 58.], [ 63.], ..., [ 88.], [ 93.], [ 98.]], [[103.], [108.], [113.], ..., [138.], [143.], [148.]], ..., [[853.], [858.], [863.], ..., [888.], [893.], [898.]], [[903.], [908.], [913.], ..., [938.], [943.], [948.]], [[953.], [958.], [963.], ..., [988.], [993.], [998.]]] **test_cc_slice_end_out_of_bounds** .. code-block:: text Node: Slice(data, starts, ends, axes, steps) -> (output) .. code-block:: text Inputs: data: shape=(20, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] starts: shape=(1,), dtype=int64 [1] ends: shape=(1,), dtype=int64 [1000] axes: shape=(1,), dtype=int64 [1] steps: shape=(1,), dtype=int64 [1] Outputs: output: shape=(20, 9, 5), dtype=float32 [[[ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], [ 15., 16., 17., 18., 19.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], [ 65., 66., 67., 68., 69.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], [115., 116., 117., 118., 119.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], [865., 866., 867., 868., 869.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], [915., 916., 917., 918., 919.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], [965., 966., 967., 968., 969.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] **test_cc_slice_neg** .. code-block:: text Node: Slice(data, starts, ends, axes, steps) -> (output) .. code-block:: text Inputs: data: shape=(20, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] starts: shape=(1,), dtype=int64 [0] ends: shape=(1,), dtype=int64 [-1] axes: shape=(1,), dtype=int64 [1] steps: shape=(1,), dtype=int64 [1] Outputs: output: shape=(20, 9, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 30., 31., 32., 33., 34.], [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 80., 81., 82., 83., 84.], [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [130., 131., 132., 133., 134.], [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [880., 881., 882., 883., 884.], [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [930., 931., 932., 933., 934.], [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [980., 981., 982., 983., 984.], [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.]]] **test_cc_slice_neg_steps** .. code-block:: text Node: Slice(data, starts, ends, axes, steps) -> (output) .. code-block:: text Inputs: data: shape=(20, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] starts: shape=(3,), dtype=int64 [20, 10, 4] ends: shape=(3,), dtype=int64 [0, 0, 1] axes: shape=(3,), dtype=int64 [0, 1, 2] steps: shape=(3,), dtype=int64 [-1, -3, -2] Outputs: output: shape=(19, 3, 2), dtype=float32 [[[999., 997.], [984., 982.], [969., 967.]], [[949., 947.], [934., 932.], [919., 917.]], [[899., 897.], [884., 882.], [869., 867.]], ..., [[199., 197.], [184., 182.], [169., 167.]], [[149., 147.], [134., 132.], [119., 117.]], [[ 99., 97.], [ 84., 82.], [ 69., 67.]]] **test_cc_slice_negative_axes** .. code-block:: text Node: Slice(data, starts, ends, axes) -> (output) .. code-block:: text Inputs: data: shape=(20, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] starts: shape=(3,), dtype=int64 [0, 0, 3] ends: shape=(3,), dtype=int64 [20, 10, 4] axes: shape=(3,), dtype=int64 [ 0, -2, -1] Outputs: output: shape=(20, 10, 1), dtype=float32 [[[ 3.], [ 8.], [ 13.], ..., [ 38.], [ 43.], [ 48.]], [[ 53.], [ 58.], [ 63.], ..., [ 88.], [ 93.], [ 98.]], [[103.], [108.], [113.], ..., [138.], [143.], [148.]], ..., [[853.], [858.], [863.], ..., [888.], [893.], [898.]], [[903.], [908.], [913.], ..., [938.], [943.], [948.]], [[953.], [958.], [963.], ..., [988.], [993.], [998.]]] **test_cc_slice_start_out_of_bounds** .. code-block:: text Node: Slice(data, starts, ends, axes, steps) -> (output) .. code-block:: text Inputs: data: shape=(20, 10, 5), dtype=float32 [[[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], ..., [ 35., 36., 37., 38., 39.], [ 40., 41., 42., 43., 44.], [ 45., 46., 47., 48., 49.]], [[ 50., 51., 52., 53., 54.], [ 55., 56., 57., 58., 59.], [ 60., 61., 62., 63., 64.], ..., [ 85., 86., 87., 88., 89.], [ 90., 91., 92., 93., 94.], [ 95., 96., 97., 98., 99.]], [[100., 101., 102., 103., 104.], [105., 106., 107., 108., 109.], [110., 111., 112., 113., 114.], ..., [135., 136., 137., 138., 139.], [140., 141., 142., 143., 144.], [145., 146., 147., 148., 149.]], ..., [[850., 851., 852., 853., 854.], [855., 856., 857., 858., 859.], [860., 861., 862., 863., 864.], ..., [885., 886., 887., 888., 889.], [890., 891., 892., 893., 894.], [895., 896., 897., 898., 899.]], [[900., 901., 902., 903., 904.], [905., 906., 907., 908., 909.], [910., 911., 912., 913., 914.], ..., [935., 936., 937., 938., 939.], [940., 941., 942., 943., 944.], [945., 946., 947., 948., 949.]], [[950., 951., 952., 953., 954.], [955., 956., 957., 958., 959.], [960., 961., 962., 963., 964.], ..., [985., 986., 987., 988., 989.], [990., 991., 992., 993., 994.], [995., 996., 997., 998., 999.]]] starts: shape=(1,), dtype=int64 [1000] ends: shape=(1,), dtype=int64 [1000] axes: shape=(1,), dtype=int64 [1] steps: shape=(1,), dtype=int64 [1] Outputs: output: shape=(20, 0, 5), dtype=float32 []